Flutter获取APP版本号

安装依赖

package_info: ^0.4.0+2

导入

import 'package:package_info/package_info.dart';

前提

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

Flutter获取APP版本号_第1张图片

获取

  • 直接获取
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)