Skip to content

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

@matanlurey

Description

@matanlurey

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

Metadata

Metadata

Labels

c: proposalA detailed proposal for a change to Flutterteam-toolOwned by Flutter Tool team

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions