-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Description
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'):
flutter/packages/flutter/lib/src/services/flutter_version.dart
Lines 22 to 24 in b73450f
| /// The Flutter channel used to compile the app. | |
| static const String? channel = | |
| bool.hasEnvironment('FLUTTER_CHANNEL') ? String.fromEnvironment('FLUTTER_CHANNEL') : null; |
flutter/packages/flutter_tools/lib/src/runner/flutter_command.dart
Lines 1492 to 1499 in b73450f
| 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