Skip to content

[flutter_tools] Allow to define --dart-define from system environment variables or from .env #56792

@TatsuUkraine

Description

@TatsuUkraine

Use case

Flutter 1.17 added the ability to define compile-time variables, which is great.

But if you have a lot of variables that you want to use in Flutter application, build and run command could become quite long.

Especially if take into account that each compile-time variable definition should start with --dart-define.

Proposal 1

Allow defining Map of Dart Defines, where keys will be used for --dart-define key, and values - Platform.environment keys.

Example

dart_defines:
  ENV: FLUTTER_APP_ENV
  APP_NAME: FLUTTER_APP_NAME

Which will be equal to
flutter run --dart-define=ENV=$FLUTTER_APP_ENV --dart-define=APP_NAME=$FLUTTER_APP_NAME

Proposal 2

Allow to use .env as source for --dart-define key

Example

ENV: SOME_ENV
APP_NAME: SOME_APP_NAME

Which will be equal to
flutter run --dart-define=ENV=SOME_APP_ENV --dart-define=APP_NAME=SOME_APP_NAME

Metadata

Metadata

Assignees

No one assigned

    Labels

    c: new featureNothing broken; request for a new capabilitytoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions