flutter package_info_plus 4.0.1版本号问题

yfwxisqw  于 2023-05-29  发布在  Flutter
关注(0)|答案(1)|浏览(335)

我尝试从PackageInfo获取应用程序的版本,但值为空。救命啊!

PackageInfo packageInfo =
   await PackageInfo.fromPlatform();
print('package info: $packageInfo');

我尝试在终端打印PackageInfo:

PackageInfo(appName: MyApp, buildNumber: 3, version: )

正如你所看到的是从响应空的版本...我也试过:

Future getVersion() async {
    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      setState(() {
        appName = packageInfo.appName;
        version = packageInfo.version;
        print('version: $version');
      });
    });
  }
093gszye

093gszye1#

import 'package:package_info_plus/package_info_plus.dart';

...

// Be sure to add this line if `PackageInfo.fromPlatform()` is called before runApp()
WidgetsFlutterBinding.ensureInitialized();

...

PackageInfo packageInfo = await PackageInfo.fromPlatform();

String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;

相关问题