12

In a Flutter app there is a version attribute in the pubspec.yaml file to specify the app version.

Is it possible to access this value from dart code when building for the web ?

sdabet
  • 18,360
  • 11
  • 89
  • 158

1 Answers1

5

There is now package_info_plus

That supports flutter for web and other platforms

Usage

import 'package:package_info_plus/package_info_plus.dart';

PackageInfo packageInfo = await PackageInfo.fromPlatform();

String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
Alex.F
  • 5,648
  • 3
  • 39
  • 63
  • 1
    Looking at the [source code](https://github.com/fluttercommunity/plus_plugins/blob/main/packages/package_info_plus_web/lib/package_info_plus_web.dart), the web implementation attempts to read package info from a specific URL "/version.json" and doesn't use the pubspec.yaml file. – sdabet Nov 23 '20 at 11:43
  • I just gave this a try and while the source code might look like it is coming from `pubspec.yaml` that is where the data is coming from. At least the version # is as that is what I was concerned with. I'd bet the URL listed in the above comment being filled with data from `pubspec.yaml` when compiled. – jaredbaszler Feb 15 '21 at 23:14
  • Hello, Flutter generates `version.json` based on `pubspec.yml` while you build for web. – Majid May 14 '21 at 15:03