Skip to content

Expose the app's build name/number as compile-time constants (complete the FlutterVersion/appFlavor pattern) #187934

Description

@Ortes

Use case

There is currently no reliable way for a Flutter application to know which version of it is actually running:

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

Implementation

A PR implementing this (tool injection mirroring the kAppFlavor guard pattern + services.dart constants + tests) is attached.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: proposalA detailed proposal for a change to Flutterhas reproducible stepsThe issue has been confirmed reproducible and is ready to work onteam-toolOwned by Flutter Tool teamtoolAffects the "flutter" command-line tool. See also t: labels.triaged-toolTriaged by Flutter Tool team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions