Learn how to use package_info_plus to get package data
Learn how to use package_info_plus to get package data
Moksh Mahajan
November 07, 2022
Generally it's a good practice to show the app version and build number in the about or similar section in the app.This might be helpful for the developers, testers and even the normal users of the app to report as well as debug any kind of bugs or unusual behaviours in the app by specifying the exact version in which they're facing any issues.
You might have seen several popular apps which do so.
Below is the screenshot from Coin
app by Zerodha
For such scenarios, there is a nice plugin from the Flutter community called package_info_plus which is an abstraction for querying details about an application package.
The package is very robust and currently supports Android, iOS, Web, macOS, Windows, and Linux.
installerStore
and buildSignature
using which we can verify if the app has been downloaded from a authentic source and has not been tampered with.For adding package_info_plus, run the following command from the project root
flutter pub add package_info_plus
Then we need to create an instance of PackageInfo class and then simply call the required package property.
PackageInfo packageInfo = await PackageInfo.fromPlatform();
print(packageInfo.version);
As the name suggests it's simply the application name.
Takes its value from:
CFBundleDisplayName
on iOS,
application/label
on Android.
This property contains the package name.
Takes its value from:
bundleIdentifier
on iOS,
getPackageName
on Android.
It conatains the semantic version value i.e major.minor.patch
.
Takes its value from:
CFBundleShortVersionString
on iOS,
versionName
on Android.
A build number is a specific identifier that lets us know what software you're running as well as when it was updated last.
Takes its value from:
CFBundleVersion
on iOS,
versionCode
on Android.
This property only exists for Android platform. It has an empty string value on iOS, signing key signature (hex) on Android.
Indicates through which store this application was installed.