Accessing package information in Flutter

Learn how to use package_info_plus to get package data

Blog Cover Image
Moksh Mahajan

Moksh Mahajan

Calender

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

photo1668147953

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.

Usecases

  1. To display the version and the build number in the app.
  2. To trigger logic such as showing app update dialog by comparing the current package version with the one on the store, or functionalities related to specific app version
  3. The plugin also exposes properties such as installerStore and buildSignature using which we can verify if the app has been downloaded from a authentic source and has not been tampered with.

Usage

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);

PakcageInfo properties description

1. appName

As the name suggests it's simply the application name.

Takes its value from: CFBundleDisplayName on iOS, application/label on Android.

2. packageName

This property contains the package name.

Takes its value from: bundleIdentifier on iOS, getPackageName on Android.

3. version

It conatains the semantic version value i.e major.minor.patch.

Takes its value from: CFBundleShortVersionString on iOS, versionName on Android.

4. buildNumber

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.

5. buildSignature

This property only exists for Android platform. It has an empty string value on iOS, signing key signature (hex) on Android.

6. installerStore

Indicates through which store this application was installed.