The keyword here is Web. I can get the build and version number of a Flutter app by using the package_info plugin, but if it is running on the web I can't. How do I get the package info for a Flutter Web app?

I'll include an answer below as a temporary fix, but I am looking a solution that gets the version info from pubspec.yaml.

解决方案

As a temporary workaround you can create a separate file with the version info in it:

web_version_info.dart

class WebVersionInfo {

static const String name = '1.0.0';

static const int build = 1;

}

You can use that for all platforms or in your code you can use kIsWeb to just use it for the web:

Future _getAppVersion() async {

if (kIsWeb) {

return WebVersionInfo.name;

} else {

PackageInfo packageInfo = await PackageInfo.fromPlatform();

return packageInfo.version;

}

}

Of course, this is not a great solution because now you need to remember to update the version and build information in both pubspec.yaml and in WebVersionInfo every time you update the app.

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐