— Flutter, Version Control, App Development — 1 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.
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.
First, add package_info_plus
to your pubspec.yaml
file:
1dependencies:2 package_info_plus: ^4.x.x
In your Dart file, import the package:
1import 'package:package_info_plus/package_info_plus.dart';
You can retrieve package information using either await/async
or then
:
await/async
:1PackageInfo packageInfo = await PackageInfo.fromPlatform();2
3String appName = packageInfo.appName;4String packageName = packageInfo.packageName;5String version = packageInfo.version;6String buildNumber = packageInfo.buildNumber;
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});
Once you have retrieved the information, you can display it in your app's UI, typically in a settings page or about dialog.
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.