This Flutter plugin provides an API for querying information about an application package.
Android | iOS | MacOS | Web | Linux | Windows |
---|---|---|---|---|---|
✔️ | ✔️ | ✔️ | ✔️ | ✔️ | ✔️ |
You can use the PackageInfo to query information about the application package. This works both on iOS and Android.
import 'package:package_info_plus/package_info_plus.dart';
...
// Be sure to add this line if `PackageInfo.fromPlatform()` is called before runApp()
WidgetsFlutterBinding.ensureInitialized();
...
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
Flutter build tools allow only digits and .
(dot) symbols to be used in version
of pubspec.yaml
on iOS/MacOS to comply with official version format from Apple.
More info available in this comment
As noted on issue 20761,
package_info_plus 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
.
Calling to PackageInfo.fromPlatform()
before the runApp()
call will cause an exception.
See fluttercommunity#309