How to get build and version number of Flutter Web app

北战南征 提交于 2020-05-17 06:59:06

问题


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.


回答1:


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<String> _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.



来源:https://stackoverflow.com/questions/60647071/how-to-get-build-and-version-number-of-flutter-web-app

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!