本文介绍了如何获取Flutter应用的内部版本和版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我当前正在开发一个处于beta模式的应用程序.因此,我想向他们展示他们使用的是哪个版本.例如,"v1.0b10-iOS".到目前为止,我已经获得了以下代码:Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android"))
.我如何才能在Flutter中获得内部版本和编号?
I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, "v1.0b10 - iOS". So far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android"))
. How would I be able to get the build version and number within flutter?
推荐答案
您可以使用 package_info
版本摘自:
Android:
build.gradle, versionCode and versionName
iOS:
Info.plist, CFBundleVersion
用法
添加依赖项
- 将此添加到您程序包的pubspec.yaml文件中:
dependencies:
package_info: ^0.4.0+16
- 将文件导入到您的dart文件中:
import 'package:package_info/package_info.dart';
- 如果您的方法标记为
async
:
PackageInfo packageInfo = await PackageInfo.fromPlatform();
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
如果您不想使用await/async
:
PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
});
这篇关于如何获取Flutter应用的内部版本和版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!