2

I need to retrieve the app version from within Dart code in a Flutter project.

I am using package_info and in Android is working OK but in iOS the version property in PackageInfo is null.

My code:

  Future<String> getVersion() async {
    String base = getText(version);
    PackageInfo packageInfo = await PackageInfo.fromPlatform();
    return base.replaceAll("[name]", packageInfo.version);
  }

Any help why is happening this or other way to retrieve the version? In some places of internet it is said that the version must be retrieved from native config files but in my case those files contains a reference to the version defined in pubspec.yaml.

I am using Flutter version 1.0.0

Thanks.

svprdga
  • 2,171
  • 1
  • 28
  • 51

2 Answers2

0

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. see this

Kundan
  • 99
  • 2
  • 4
0

Add below two line in your plist file inside dict:

<key>CFBundleDisplayName</key>
<string>Package Info Example</string>
halfer
  • 19,824
  • 17
  • 99
  • 186
Mir Mahfuz
  • 663
  • 4
  • 9