Scriptim
Scriptim

Reputation: 1832

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.

Upvotes: 5

Views: 4938

Answers (3)

Guvanch
Guvanch

Reputation: 1288

Stopping the running app, and start again works

Upvotes: 0

diegoveloper
diegoveloper

Reputation: 103541

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

Upvotes: 1

Kundan
Kundan

Reputation: 99

This package_info on iOS requires the Xcode build folder to be rebuilt after changes to the version string in pubspec.yaml. Clean the Xcode build folder with: XCode Menu -> Product -> (Holding Option Key) Clean build folder.

Upvotes: 0

Related Questions