flutterversion

How to get build and version number of Flutter app


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 far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android")). How would I be able to get the build version and number within flutter?


Solution

  • You can use package_info_plus.

    The versions are extracted from:

    Android:

    build.gradle, versionCode and versionName
    

    iOS:

    Info.plist, CFBundleVersion
    

    Usage

    Add the dependency

    1. Add this to your package's pubspec.yaml file:
    dependencies:
      package_info_plus: ^1.0.6
    
    1. Import the file into your dart file:
    import 'package:package_info_plus/package_info_plus.dart';
    
    1. if your method is marked as async:
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    
    String appName = packageInfo.appName;
    String packageName = packageInfo.packageName;
    String version = packageInfo.version;
    String buildNumber = packageInfo.buildNumber;
    

    If you don't want to use await/async:

    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      String appName = packageInfo.appName;
      String packageName = packageInfo.packageName;
      String version = packageInfo.version;
      String buildNumber = packageInfo.buildNumber;
    });