Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Proposal: flutter config flags can be read from FlutterVersion.flags #167668

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
matanlurey opened this issue Apr 23, 2025 · 6 comments
Open

Proposal: flutter config flags can be read from FlutterVersion.flags #167668

matanlurey opened this issue Apr 23, 2025 · 6 comments
Assignees
Labels
c: proposal A detailed proposal for a change to Flutter fyi-framework For the attention of Framework team team-tool Owned by Flutter Tool team

Comments

@matanlurey
Copy link
Contributor

In the main (and I believe, beta) channels of Flutter, FlutterVersion exists and is provided various primitive values from .fromEnvironment flags passed by the tool. For example, FlutterVersion.channel comes from String.fromEnvironment('FLUTTER_CHANNEL'):

/// The Flutter channel used to compile the app.
static const String? channel =
bool.hasEnvironment('FLUTTER_CHANNEL') ? String.fromEnvironment('FLUTTER_CHANNEL') : null;

dartDefines.addAll(<String>[
'$flutterVersionDefine=${version.frameworkVersion}',
'$flutterChannelDefine=${version.channel}',
'$flutterGitUrlDefine=${version.repositoryUrl}',
'$flutterFrameworkRevisionDefine=${version.frameworkRevisionShort}',
'$flutterEngineRevisionDefine=${version.engineRevisionShort}',
'$flutterDartVersionDefine=${version.dartSdkVersion}',
]);

This proposal would add an additional field or field(s - perhaps one for "enabled" and one for "disabled", for example, if we didn't want to say, pass a JSON-encoded string), $flutterFeatureFlags=${...}, in order to expose the following within the Flutter runtime:

abstract final class FlutterVersion {
  // ...
  static final Map<String, bool> flags = Map.unmodifiable({ /* TBD: Implementation */});
}

This map could be used:

  • As a reporting mechanism, i.e. to Sentry or Firebase Crashlytics
  • As a gating mechanism, i.e. for features that are not yet stable (sensitive content?)
  • As a behavioral mechanism, i.e. for features we'd like to change the behavior of conditionally
  • As an "informed deprecation" mechanism, requiring the user to explicitly opt-in to an older API

@loic-sharma has some legitimate follow-up requests that we are careful about the use of FlutterVersion.flags in the framework code, and instead might want to lint for it, and provide a typed API that translates, which seems reasonable:

final class FlutterFlags {
  // ...
  bool get isFooEnabled => FlutterVersion['foo'] == true;
}

... but I'll leave out the specifics for now.

See also: #167667

/cc @ueman @bkonyi @loic-sharma @jtmcdole @camsim99

@matanlurey matanlurey added c: proposal A detailed proposal for a change to Flutter fyi-framework For the attention of Framework team team-tool Owned by Flutter Tool team labels Apr 23, 2025
@loic-sharma
Copy link
Member

Tests will likely need to control whether a feature is on/off. We might want to put the flags on the binding system (perhaps BindingBase directly) to allow mocking feature flags

@ueman
Copy link
Contributor

ueman commented Apr 24, 2025

Depending on the size of the features that can be toggled, you want to make sure they're properly tree-shakable

@matanlurey
Copy link
Contributor Author

@loic-sharma has volunteered to write the initial PR, we can still discuss before landing.

@matanlurey matanlurey assigned loic-sharma and unassigned justinmc Apr 29, 2025
@matanlurey
Copy link
Contributor Author

@loic-sharma Any update? I can take this over if you're busy with something else.

@loic-sharma
Copy link
Member

@matanlurey I have a prototype here: https://github.com/loic-sharma/flutter/tree/framework_feature_flags

My time is a bit split this week. I should be able to send something more concrete soon, but feel free to steal it back if you'd like. :)

@matanlurey
Copy link
Contributor Author

No worries, I just wanted to make sure it wasn't totally stalled. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: proposal A detailed proposal for a change to Flutter fyi-framework For the attention of Framework team team-tool Owned by Flutter Tool team
Projects
None yet
Development

No branches or pull requests

4 participants