Skip to content

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

Open

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.

Activity

  1. added
    toolAffects the "flutter" command-line tool. See also t: labels.
    on Dec 14, 2018
  2. added this to the milestone on Dec 14, 2018
  3. zoechi commented on Dec 19, 2018

    @zoechi
    Contributor

    Are #9870, #16204, #13834 duplicates/related?

  4. tvolkert commented on Dec 19, 2018

    @tvolkert
    ContributorAuthor

    Yep! I closed the others to centralize on this one since it provides the most detail in the description.

  5. jonahwilliams commented on Jan 25, 2019

    @jonahwilliams
    Contributor

    I'm currently working on integration between the flutter tool and build_runner so that code generation can be fully managed by the tool. That means generators are run at appropriate times (before hot reload, analyze, tests) and knowledge of builders is incorporated into the tool and messaging.

    There is a lot of ground to cover in terms of making sure it is performant and works with all of the existing flutter commands. During this time, it will be be available as an "experiment" behind a flag for developers interested in trying it out.

  6. jonahwilliams commented on Jan 28, 2019

    @jonahwilliams
    Contributor

    If you're interested in support for code generation please follow (and thumbs up) #27141

  7. jonahwilliams commented on Feb 5, 2019

    @jonahwilliams
    Contributor

    One concrete use-case for this API: allow plugging into Bazel.

  8. jonahwilliams commented on Apr 21, 2019

    @jonahwilliams
    Contributor

    This came up again during discussions about Linux run/build support with @stuartmorgan. The idea is to provide minimal Dart APIs and then support a simplified plugin interface. The tool could then execute each plugin in an isolate and communicate via json.

    Example:
    my_app/pubspec.yaml

    tool_plugin:
      - linux_device_clang # refers to a pub package, no version since that is constrained via the tool
    

    We provide a minimal set of interfaces that can be implemented to define a device & workflow. These could be defined in flutter_tools/lib/api. Alternatively, we could define a separate pub package that the flutter_tool uses, or figure out distribution later.

    class Plugin {
      Future<List<Device>> get devices;
      
      Future<String> get doctor;
    }
    
    // Minimal version of existing device type.
    class Device {
      ...
    }
    

    A user defined plugin might require some additional configuration, from which we can generate an entrypoint.

    linux_clang_device/tool_plugin.yaml

    plugin: lib/linux_clang_device.yaml
    name:  linuxToolPlugin
    

    When running the tool, we check for plugins and run generation if it hasn't run before. Then on certain commands we invoke methods across the isolate boundary using a JSON api which we control/generate via the entrpoint generation. The generated code would be responsible for turning the json into typed/documented method calls

    flutter_tools                                linux_clang_device
    `flutter devices`               ->           {"method":  "getDevices"}
                                    <-           {"id": "some_id"}
    `flutter run -d some_id         ->           {"method": "run", "artifactLocations": [], "projectDirectory": ...}
    
  9. vishna commented on Sep 26, 2019

    @vishna

    so my use case would be to invoke CLI command, e.g.:

    echo "Hello world"
    

    before compilation begins/hot reloads

    This ticket #9870 seemed more like a right place to ask for it, but got closed as a duplicate 🤷‍♂

  10. changed the title [-]Provide an API in the Flutter tool[/-] [+]Provide an API in the Flutter tool to make it extensible[/+] on Jan 3, 2020
  11. DanTup commented on Feb 20, 2020

    @DanTup
    Contributor

    This was sent to me on Twitter as something that would be neat to support from VS Code:

    https://pub.dev/packages/device_preview

    It would be hard to do from the IDE (currently it requires code changes or its own entry point, and modifying/writing files from the IDE would be clunky), but I wonder if it'd fit in here (it'd also work for other IDEs and command line users if wired up here).

  12. aloisdeniel commented on Feb 20, 2020

    @aloisdeniel
  13. jonahwilliams commented on Feb 20, 2020

    @jonahwilliams
  14. 28 remaining items

  15. self-assigned this
    on Jun 30, 2025
  16. added
    tool-still-validIssues that have been deemed still valid as part of the Flutter Tools issue cleanup initiative.
    on Jun 30, 2025
  17. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Nov 3, 2025
  18. flutter-triage-bot commented on Nov 3, 2025

    @flutter-triage-bot

    This issue is assigned to @bkonyi but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  19. flutter-triage-bot commented on Nov 18, 2025

    @flutter-triage-bot

    This issue is assigned to @bkonyi but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  20. flutter-triage-bot commented on Jan 23, 2026

    @flutter-triage-bot

    This issue was assigned to @bkonyi but has had no status updates in a long time. To remove any ambiguity about whether the issue is being worked on, the assignee was removed.

  21. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Jan 23, 2026
  22. self-assigned this
    on Jan 26, 2026
  23. added
    ⏳Bot is counting down the days until it unassigns the issue
    on Jun 1, 2026
  24. flutter-triage-bot commented on Jun 1, 2026

    @flutter-triage-bot

    This issue is assigned to @bkonyi but has had no recent status updates. Please consider unassigning this issue if it is not going to be addressed in the near future. This allows people to have a clearer picture of what work is actually planned. Thanks!

  25. bkonyi commented on Jun 1, 2026

    @bkonyi
    Contributor

    This is actively being investigated, but nothing to report yet.

  26. removed
    ⏳Bot is counting down the days until it unassigns the issue
    on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.triaged-toolTriaged by Flutter Tool team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions