Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Flutter version from code?

Tags:

flutter

How can I get Flutter version from code?

I want to include the Flutter version in API UserAgent and logs.

like image 712
najeira Avatar asked Sep 01 '17 12:09

najeira


People also ask

What is version code Flutter?

The version number is three numbers separated by dots, such as 1.0.0 in the example above, followed by an optional build number such as 1 in the example above, separated by a + . Both the version and the build number may be overridden in Flutter's build by specifying --build-name and --build-number , respectively.

How can I get Android version programmatically in Flutter?

To get the device operating system version that your Flutter app is running on, just import dart:io and use Platform. operatingSystemVersion. No third-party package or installation is required.

What is version code and version name?

version code ( android:versionCode on your AndroidManifest. xml ) . The version code is an incremental integer value that represents the version of the application code. The greatest value Google Play allows for version code is 2100000000. version name ( android:versionName on your AndroidManifest.


1 Answers

I guess you need a custom build script that creates a file like

lib/src/flutter_version.dart

with content like

const String version = const <String,String>
{
  "channel": "alpha",
  "repositoryUrl": "https://github.com/flutter/flutter.git",
  "frameworkRevision": "d36e2f6191793de66e0a132ad8c86885829bc6b2",
  "frameworkCommitDate": "2017-06-21 15:09:10 -0700",
  "engineRevision": "b0dee695ecb9ea2438f4d74afdca45839858c311",
  "dartSdkVersion": "1.24.0-dev.6.7"
};

which you can create by

echo "const String version = const \<String,String\>" > lib/src/flutter_version.dart
flutter --version --machine >> lib/src/flutter_version.dart
echo ";" >> lib/src/flutter_version.dart

You can then just import it and read the value

import 'package:my_package/src/flutter_version';

main() {
  print(version['frameworkRevision']);
}

For other device information there is also https://github.com/flutter/plugins/tree/master/packages/device_info

like image 68
Günter Zöchbauer Avatar answered Nov 14 '22 20:11

Günter Zöchbauer