You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There is currently no reliable way for a Flutter application to know which version of it is actually running:
On Android/iOS/macOS, plugins like package_info_plus read the version from the installed binary — reliable, but requires a plugin and a platform channel for a value the tool knew at compile time.
We hit this in production: users stuck for weeks on an outdated web bundle because the minimum-version gate compared the server's version against the server's minimum.
Proposal
Complete a pattern the tool already implements. flutter_tools already injects as dart-defines:
FLUTTER_VERSION, FLUTTER_CHANNEL, FLUTTER_GIT_URL, FLUTTER_FRAMEWORK_REVISION, FLUTTER_ENGINE_REVISION, FLUTTER_DART_VERSION → exposed as FlutterVersion constants in package:flutter/services.dart
FLUTTER_APP_FLAVOR → exposed as appFlavor
The application's own version: from pubspec.yaml is the single missing field — even though the tool already parses it (FlutterManifest.buildName/buildNumber) and already embeds it into version.json, Info.plist, and build.gradle on every build.
Proposed: inject FLUTTER_BUILD_NAME / FLUTTER_BUILD_NUMBER (from --build-name/--build-number, falling back to the pubspec version) exactly like FLUTTER_APP_FLAVOR, and expose them as appBuildName / appBuildNumber constants in services.dart. A compile-time constant is by definition the version of the code that is executing — it cannot diverge from the running bundle, works offline, and needs no platform channel.
Privacy/size note: like every String.fromEnvironment constant, these are tree-shaken when unreferenced — nothing ships in the binary unless the app actually reads them. (The tool also already embeds strictly more metadata unconditionally via FlutterVersion, including the SDK git URL.)
Prior art / history
"Static" versioning in flutter web #149725 asked for exactly this and was closed as a "Dart language feature request" after a supportive comment from the web team — but the value can only come from the front-end that parses pubspec.yaml, which for Flutter apps is flutter_tools, not the Dart SDK. The thread is now locked, hence this issue.
Use case
There is currently no reliable way for a Flutter application to know which version of it is actually running:
package_info_plusread the version from the installed binary — reliable, but requires a plugin and a platform channel for a value the tool knew at compile time.package_info_plusfetchesversion.jsonfrom the server at runtime (with a cache buster). That file reflects the currently deployed version — not the (possibly stale, cached) bundle executing in the browser. A stale client therefore self-reports as up to date, and every "please update" gate or version display built on it silently fails for exactly the users it exists for ([Bug]: [package_info_plus] Web: Version info returns next version in server fluttercommunity/plus_plugins#2675, also Support text selections #225, Import path.dart as path rather than p #456). This is silently shipping wrong version numbers in production apps today, through a Flutter Favorite package.We hit this in production: users stuck for weeks on an outdated web bundle because the minimum-version gate compared the server's version against the server's minimum.
Proposal
Complete a pattern the tool already implements.
flutter_toolsalready injects as dart-defines:FLUTTER_VERSION,FLUTTER_CHANNEL,FLUTTER_GIT_URL,FLUTTER_FRAMEWORK_REVISION,FLUTTER_ENGINE_REVISION,FLUTTER_DART_VERSION→ exposed asFlutterVersionconstants inpackage:flutter/services.dartFLUTTER_APP_FLAVOR→ exposed asappFlavorThe application's own
version:frompubspec.yamlis the single missing field — even though the tool already parses it (FlutterManifest.buildName/buildNumber) and already embeds it intoversion.json,Info.plist, andbuild.gradleon every build.Proposed: inject
FLUTTER_BUILD_NAME/FLUTTER_BUILD_NUMBER(from--build-name/--build-number, falling back to the pubspec version) exactly likeFLUTTER_APP_FLAVOR, and expose them asappBuildName/appBuildNumberconstants inservices.dart. A compile-time constant is by definition the version of the code that is executing — it cannot diverge from the running bundle, works offline, and needs no platform channel.Privacy/size note: like every
String.fromEnvironmentconstant, these are tree-shaken when unreferenced — nothing ships in the binary unless the app actually reads them. (The tool also already embeds strictly more metadata unconditionally viaFlutterVersion, including the SDK git URL.)Prior art / history
pubspec.yaml, which for Flutter apps isflutter_tools, not the Dart SDK. The thread is now locked, hence this issue.dart compile(servers/CLIs); neither side subsumes the other since Flutter does not build throughdartdev.package_info_plusis ready to consume these defines the moment they exist, making the fix transparent for the whole ecosystem.Implementation
A PR implementing this (tool injection mirroring the
kAppFlavorguard pattern +services.dartconstants + tests) is attached.