10

How can I get Flutter version from code?

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

1 Answer 1

7

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

Sign up to request clarification or add additional context in comments.

3 Comments

After 3 years, is there any directly function that can query flutter version form code?
Perhaps pub.dev/packages/package_info provides the info you want (haven't checked in a while what exactly it provides).
That is "App Version", not Flutter version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.