在pubspec.yaml文件中确保已经有 package_info 的版本信息
dependencies:flutter:sdk: flutterpackage_info: ^2.0.2 //添加这一行
引用
import 'package:package_info/package_info.dart';Future<void> getVersion() async {PackageInfo packageInfo = await PackageInfo.fromPlatform();return packageInfo.version
}