2026-10-10-version-from-platform
title: Read the app version from the platform build affects: dartway_cli: "0.25.0-dev.0"
Who is affected
Projects whose Flutter entrypoint passes a committed appBuildVersion constant.
Apply this change on the next template sync. An empty platform build number maps
to build 0. In the template, an empty version or a failed platform read is
reported with its stack trace via debugPrint before using 0.0.0+0 so startup
continues. The read precedes the app's uncaught-error pipeline; these fallbacks
are template behaviour.
What to change
-
Add
package_info_plus: ^9.0.1to the Flutter package's dependencies and runflutter pub get. -
Delete
lib/core/app_version.dartandtest/core/app_version_test.dart, and remove their imports. The widget harness intest/support/app_test_app.dartpasses a literal such as'0.0.0+0'toAppDwCore.create. -
Make
mainasynchronous and read the platform version before running the app:import 'package:flutter/foundation.dart';import 'package:flutter/widgets.dart';import 'package:package_info_plus/package_info_plus.dart';Future<void> main() async {WidgetsFlutterBinding.ensureInitialized();final appVersion = await readAppVersion();// Pass appVersion to the application's existing app constructor and run it.}Future<String> readAppVersion() async {final PackageInfo info;try {info = await PackageInfo.fromPlatform();} catch (error, stackTrace) {// The app's uncaught-error pipeline is installed after this read.debugPrint('Could not read app version: $error\n$stackTrace');return '0.0.0+0';}return appVersionOf(info);}String appVersionOf(PackageInfo info) {if (info.version.isEmpty) {debugPrint('Platform app version is empty.\n${StackTrace.current}');return '0.0.0+0';}return info.buildNumber.isEmpty? '${info.version}+0': '${info.version}+${info.buildNumber}';} -
Keep the marketing version in
pubspec.yaml; its+Nis only a fallback for local builds. Pass--build-number=Nin release builds and use--build-nameonly when overriding the marketing version. N will come from Studio's per-project counter. Do not commit release build-number bumps.
On web, PackageInfo reads the version.json that flutter build web writes.
The web Dockerfile and deploy flow are unchanged; until the release counter is
wired, that web build uses pubspec's fallback build number. Dw-App-Version labels sessions
and decides nothing about compatibility.
How to check
Test appVersionOf with a supplied build number and an empty one (+0), and
with an empty version (0.0.0+0). Test that readAppVersion returns 0.0.0+0
when reading the platform version throws, and that both fallbacks report the
problem and its stack trace before continuing.
Run flutter test, then build and run web and a mobile simulator build with
--build-number=521. AppVersionLabel should show the marketing version followed
by +521, while pubspec.yaml remains unchanged.