Skip to content

Provide an API in the Flutter tool to make it extensible #25377

@tvolkert

Description

@tvolkert

Edit by @christopherfujino a design doc for this proposal is at https://flutter.dev/go/flutter-tool-extension-api


Right now, the Flutter tool is somewhat extensible by wrapping main() in a project-specific main() method, that uses combinations of AppContext.run() and the top-level run() function to override certain behaviors of the tool:

for instance, the code would look something like this:

import 'package:flutter_tools/runner.dart' as runner;
import 'package:flutter_tools/src/base/context.dart';
import 'package:flutter_tools/src/commands/config.dart';
import 'package:flutter_tools/src/commands/daemon.dart';
import 'package:flutter_tools/src/commands/devices.dart';
import 'package:flutter_tools/src/commands/logs.dart';
import 'package:flutter_tools/src/runner/flutter_command.dart';

Future<Null> main(List<String> args) async {
  final Map<Type, Generator> overrides = await _getProjectSpecificOverrides();

  await context.run(
    overrides: overrides,
    body: () {
      return runner.run(args, <FlutterCommand>[
        new _ProjectSpecificAttachCommand(),
        new ConfigCommand(),
        new DaemonCommand(),
        new DevicesCommand(),
        new _ProjectSpecificDoctorCommand(),
        new LogsCommand(),
        new _ProjectSpecificRunCommand(),
      ]);
    },
  );
}

The problem with this is that in order to accomplish this behavior, the project has to reach into implementation files in flutter_tools, as well as the fact that this is all undocumented because it's not an official API.

There are a growing number of use cases for making the Flutter tool extensible, such as allowing project to:

For a targeted set of use cases, we should expose an API in the Flutter tool for how such projects could import & extend the tool.

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listc: new featureNothing broken; request for a new capabilitycustomer: crowdAffects or could affect many people, though not necessarily a specific customer.team-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions