此Flutter插件提供了一个API,用于查询有关应用程序包的信息。
添加依赖
dependencies:
package_info: ^0.4.0+1
安装
flutter packages get
使用
您可以使用PackageInfo查询有关应用程序包的信息。这适用于iOS和Android。
import 'package:package_info/package_info.dart';
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
或者异步模式
PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
});