我当前正在开发一个处于beta模式的应用程序。因此,我想向他们展示它们的版本。例如,“ v1.0b10-iOS”。到目前为止,我已经收到以下代码:Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android"))。我如何才能在Flutter中获得内部版本和编号?
Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android"))
您可以使用package_info。
这些版本摘自:
Android:
build.gradle, versionCode and versionName
iOS:
Info.plist, CFBundleVersion
dependencies: package_info: ^0.4.0+16
将文件导入到dart文件中:
import ‘package:package_info/package_info.dart’;
如果您的方法标记为async:
async
PackageInfo packageInfo = await PackageInfo.fromPlatform(); String appName = packageInfo.appName; String packageName = packageInfo.packageName; String version = packageInfo.version; String buildNumber = packageInfo.buildNumber;
如果您不想使用await/async:
await/async
PackageInfo.fromPlatform().then((PackageInfo packageInfo) { String appName = packageInfo.appName; String packageName = packageInfo.packageName; String version = packageInfo.version; String buildNumber = packageInfo.buildNumber; });