2

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

3 Answers 3

2

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),
Sign up to request clarification or add additional context in comments.

Comments

1

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");
    }

Comments

0

Here is my working solution addressing directly the version inside the pubspec.yaml:

class AppVersionWidget extends StatefulWidget {

  const AppVersionWidget({super.key});

  @override
  TabAboutInformationState createState() => TabAboutInformationState();
}

class AppVersionWidgetState extends State<AppVersionWidget> {
  late String appVersion = '?';

  @override
  void initState() {
    super.initState();
    getAppVersion();
  }

  Future<void> getAppVersion() async {
    PackageInfo packageInfo = await PackageInfo.fromPlatform();

    setState(() {
      appVersion = packageInfo.version;
    });
  }

  @override
  Widget build(BuildContext context) {
    return Text(appVersion);
  }
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.