enableFlutterDriverExtension function Null safety

void enableFlutterDriverExtension (
  1. {DataHandler handler,
  2. bool silenceErrors: false,
  3. List<FinderExtension> finders}

Enables Flutter Driver VM service extension.

This extension is required for tests that use package:flutter_driver to drive applications from a separate process. In order to allow the driver to interact with the application, this method changes the behavior of the framework in several ways - including keyboard interaction and text editing. Applications intended for release should never include this method.

Call this function prior to running your application, e.g. before you call runApp.

Optionally you can pass a DataHandler callback. It will be called if the test calls FlutterDriver.requestData.

silenceErrors will prevent exceptions from being logged. This is useful for tests where exceptions are expected. Defaults to false. Any errors will still be returned in the response field of the result JSON along with an isError boolean.

The finders parameter are used to add custom finders, as in the following example.

void main() {
  enableFlutterDriverExtension(finders: <FinderExtension>[ SomeFinderExtension() ]);

class Some extends SerializableFinder {
  const Some(this.title);

  final String title;

  String get finderType => 'Some';

  Map<String, String> serialize() => super.serialize()..addAll(<String, String>{
    'title': title,
class SomeFinderExtension extends FinderExtension {

 String get finderType => 'Some';

 SerializableFinder deserialize(Map<String, String> params, DeserializeFinderFactory finderFactory) {
   return Some(json['title']);

 Finder createFinder(SerializableFinder finder) {
   Some someFinder = finder as Some;

   return find.byElementPredicate((Element element) {
     final Widget widget = element.widget;
     if (element.widget is SomeWidget) {
       return element.widget.title == someFinder.title;
     return false;


void enableFlutterDriverExtension({ DataHandler handler, bool silenceErrors = false, List<FinderExtension> finders}) {
  assert(WidgetsBinding.instance == null);
  _DriverBinding(handler, silenceErrors, finders ?? <FinderExtension>[]);
  assert(WidgetsBinding.instance is _DriverBinding);