I have the most strange behaviour in Flutter, and I can’t for the life of me figure out why it happens. It is not a critical bug in any way, I am just so annoyed that I can’t find the reason for it!
I have a Flutter-app, that is built for iOS and Android. The dependency Package Info Plus is used to retrieve the app version and build number using this simple widget:
class AppVersionWidget extends StatelessWidget {
const AppVersionWidget({super.key});
@override
Widget build(BuildContext context) => FutureBuilder<String>(
future: _getAppVersion(),
builder: (context, snapshot) => snapshot.hasData
? Text(
'v${snapshot.data}',
style: context.textTheme.bodySmall!.apply(
color: context.customColorScheme?.whiteFixed,
),
textAlign: TextAlign.center,
)
: const SizedBox.shrink(),
);
Future<String> _getAppVersion() async {
final packageInfo = await PackageInfo.fromPlatform();
final appVersion = packageInfo.version;
final buildVersion = packageInfo.buildNumber;
return '$appVersion ($buildVersion)';
}
}
On iOS, this works perfectly, if the app version is 1.0.0
and the build number is 123
, it will output 1.0.0 (123)
. On android however, it outputs 1.0.0 (2123)
. I have tried different build numbers, and realised that on android, the number 2000 is always added to the build number. If I change build number to 12345
, it will output 14345
. Why???
I have done some debugging, in build.gradle
I added the following:
println "Debug Output: Version Code = ${flutterVersionCode}"
println "Debug Output: Version Name = ${flutterVersionName}"
And during the Android build-process, it correctly outputs:
Debug Output: Version Code = 123
Debug Output: Version Name = 1.0.0
No one else seems to have this issue when I search for it, so I don’t really know what else to try or what the reason might be?!