How to get build and version number of Flutter app

后端 未结 4 1469
旧巷少年郎
旧巷少年郎 2020-12-14 05:03

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, \"v1.0b10 - iOS\". So

4条回答
  •  太阳男子
    2020-12-14 05:55

    There is a plugin that will help you get the version name and number.

    Add the dependency

    In pubspec.yaml add the package_info package.

    dependencies:
      package_info: ^0.4.0+13
    

    Update the version number to the current one.

    Import the package

    In the file that you need it, add the following import.

    import 'package:package_info/package_info.dart';
    

    Get the version name and code

    In your code you can get the app version name and code like this:

    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    String versionName = packageInfo.version;
    String versionCode = packageInfo.buildNumber;
    

    See also

    • How to set build and version number of Flutter app
    • How to get build and version number of Flutter Web app

提交回复
热议问题