Introducing Flutter's PackageInfo Plugin: Accessing App Package Information

Published on by Flutter News Hub

Introducing Flutter's PackageInfo Plugin: Accessing App Package Information

Overview

Flutter's PackageInfo plugin empowers developers with access to vital information about their app packages, including the app name, package name, version number, and build number. This plugin seamlessly supports both iOS and Android platforms.

Usage

Integrating the PackageInfo plugin into your Flutter app is straightforward:

import 'package:package_info/package_info.dart';

Future main() async {
  // Get package information
  PackageInfo packageInfo = await PackageInfo.fromPlatform();

  // Access package details
  String appName = packageInfo.appName;
  String packageName = packageInfo.packageName;
  String version = packageInfo.version;
  String buildNumber = packageInfo.buildNumber;

  // Use the package information as needed
  print('App name: $appName');
  print('Package name: $packageName');
  print('Version: $version');
  print('Build number: $buildNumber');
}

Asynchronous Access

For asynchronous retrieval of package information:

PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
  // Access package details
  String appName = packageInfo.appName;
  String packageName = packageInfo.packageName;
  String version = packageInfo.version;
  String buildNumber = packageInfo.buildNumber;

  // Use the package information as needed
});

Benefits of PackageInfo

The PackageInfo plugin offers several advantages:

  • Centralized Access: It provides a single source for package information, eliminating the need to manually collect and parse it from multiple sources.
  • Platform Independence: It works seamlessly on both iOS and Android platforms, ensuring consistency across different devices and operating systems.
  • Improved Deployment: By accessing package information, developers can optimize app deployment and versioning for specific platforms.

Known Issue: iOS Xcode Build Folder

For iOS platforms, changes to the version string in the pubspec.yaml file require rebuilding the Xcode build folder. To resolve this issue:

  • Go to Xcode Menu > Product.
  • Hold down the Option key.
  • Select "Clean build folder" to rebuild the folder.
Flutter News Hub