我需要从pubspec. yaml访问版本并将其显示在屏幕上。我如何才能在不使用任何软件包的情况下获得此功能。任何答案都将不胜感激。谢谢
在此处输入图像描述
试试这个包。根据示例,用法如下。
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;
或者检查这个答案