-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
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:
| Future<int> run( |
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:
- wire up code generation as part of their build (and likewise for hot reload)
- wire up C/C++ compilation as part of their build (moreso when Design and implement Dart VM FFI dart-lang/sdk#34452 and Support integrating with C/C++ in plugin framework #7053 are implemented)
- Support a different enumeration of device types (e.g. desktop embedders)
- Expose a Flutter tool "plugin", such that other Flutter projects can customize their developer experience just by installing a set of plugins
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.