Home > Mobile >  Retrieve the current version of the app from pubspec.yaml
Retrieve the current version of the app from pubspec.yaml

Time:10-12

How will I access the current version of the app so that I can at least show in Text Widget?

CodePudding user response:

You can set the app version as an environment variable in your build config like so:

flutter build apk --dart-define=APPVERSION=1.0.0

then use it in the code like so:

const String APPVERSION =
String.fromEnvironment('APPVERSION', defaultValue: 'dev-build');

You can then use this in your text widget like so:

Text(APPVERSION),

CodePudding user response:

Try out package_info package:-

PackageInfo packageInfo = await PackageInfo.fromPlatform();

    if (Platform.isAndroid) {
      var androidAppVersion = packageInfo.version;
      log("Android Version---->$androidAppVersion");
      log("Build Number---->${packageInfo.buildNumber}");
    } else {
      var iosAppVersion = packageInfo.version;
      log("Ios Version---->$iosAppVersion");
    }
  • Related