Skip to content
DeveloperMemos

Getting Build and Version Number in Flutter Apps

Flutter, Version Control, App Development1 min read

In Flutter app development, displaying the build and version number can be crucial, especially during the testing or beta phases. This article demonstrates how to retrieve these details using the package_info_plus package.

Using package_info_plus

package_info_plus is a Flutter package that allows you to access various information about your application package, including the app name, package name, version, and build number.

Adding the Dependency

First, add package_info_plus to your pubspec.yaml file:

1dependencies:
2 package_info_plus: ^4.x.x

Importing the Package

In your Dart file, import the package:

1import 'package:package_info_plus/package_info_plus.dart';

Retrieving Package Information

You can retrieve package information using either await/async or then:

Using await/async:

1PackageInfo packageInfo = await PackageInfo.fromPlatform();
2
3String appName = packageInfo.appName;
4String packageName = packageInfo.packageName;
5String version = packageInfo.version;
6String buildNumber = packageInfo.buildNumber;

Using then:

1PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
2 String appName = packageInfo.appName;
3 String packageName = packageInfo.packageName;
4 String version = packageInfo.version;
5 String buildNumber = packageInfo.buildNumber;
6});

Displaying the Version and Build Number

Once you have retrieved the information, you can display it in your app's UI, typically in a settings page or about dialog.

Example:

1Text('App Version: $version ($buildNumber)')

Retrieving and displaying the build and version number in Flutter apps is straightforward with the package_info_plus package. This functionality is essential for keeping users informed about the app version, especially during testing and development stages.