flutter获取APP版本号

安装依赖
package_info: ^XXX

导入
import 'package:package_info/package_info.dart';

前提
我们要在pubspec.yaml中设置版本号

直接获取

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;
});

你可能感兴趣的:(flutter获取APP版本号)