Search code examples
pluginsflutterversion

Flutter: package_info.version is always "1.0"


I'm trying to get my Flutter app's version using the package_info plugin.

import 'package:package_info/package_info.dart';
// ...
PackageInfo.fromPlatform().then((pkgInfo) {
  print(pkgInfo.version); // prints "1.0"
});

However, in pubspec.yaml, I specified version: 2.0.0.

Where does the plugin get the version numer from? How can I change it?

Incidentally, pkgInfo.appName matches the name field in pubspec.yaml.


Solution

  • It's not the version from pubspec.yaml, it's the version from Android / iOS platform. So you should change the version in :

    Android

    android/app/build.gradle file

        versionCode 5
        versionName "1.0"
    

    iOS

    ios/Runner/Info.plist file

    <key>CFBundleShortVersionString</key>
        <string>1.0</string>
    

    UPDATE

    package_info is deprecated, use package_info_plus instead.

    For more information you can check how the native package get the version for each platform:

    https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus/package_info_plus/lib/package_info_plus.dart#L47