Get App Info with package_info_plus in Flutter

Published on by Flutter News Hub

Get App Info with package_info_plus in Flutter

The package_info_plus plugin simplifies retrieving various details about your Flutter app, including its name, version, and build number, across multiple platforms. Here's how you can use it:

Installation

  1. Add the dependency to your pubspec.yaml file:
dependencies:
  package_info_plus: ^1.7.0
  1. Run flutter pub get to install the plugin.

Usage

Import the plugin into your Dart code:

import 'package:package_info_plus/package_info_plus.dart';

To access the package information, call PackageInfo.fromPlatform():

Future packageInfo = PackageInfo.fromPlatform();

From the PackageInfo object, you can obtain the following details:

  • appName: Name of the app
  • packageName: Unique identifier of the app
  • version: Version of the app
  • buildNumber: Build number of the app

Sample Code

PackageInfo packageInfo = await PackageInfo.fromPlatform();
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;

Platform Support

The plugin supports the following platforms:

  • Android
  • iOS
  • macOS
  • Web
  • Linux
  • Windows

Known Issues

iOS

  • Incorrect app version: Ensure that your pubspec.yaml version follows Apple's official version format (digits and dots only).
  • Wrong info after pubspec.yaml version change: Clean the Xcode build folder (Product -> Clean Build Folder).

Android (Potentially All Platforms)

  • Exception before runApp(): Call PackageInfo.fromPlatform() after runApp().

Web

  • Wrong version: Ensure that the version.json file is accessible without CORS issues.

Additional Resources

Flutter News Hub