简体   繁体   中英

How to get build and version number of Flutter app

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, "v1.0b10 - iOS". So far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS? "iOS": "Android")) . How would I be able to get the build version and number within flutter?

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, "v1.0b10 - iOS". So far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android")) . How would I be able to get the build version and number within flutter?

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, "v1.0b10 - iOS". So far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android")) . How would I be able to get the build version and number within flutter?

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, "v1.0b10 - iOS". So far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android")) . How would I be able to get the build version and number within flutter?

RE 多次引用package_info ,请注意这个包已被弃用,推荐的替换是Flutter Community Plus 插件版本package_info_plus

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, "v1.0b10 - iOS". So far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android")) . How would I be able to get the build version and number within flutter?

For using it from command line or CLI, you need a pure Dart code.

I used the following script:

// ignore_for_file: avoid_print
import 'dart:io';

import 'package:path/path.dart';
import 'package:yaml/yaml.dart';

String pathToYaml = join(dirname(Platform.script.toFilePath()), '../pubspec.yaml');

Future<YamlMap> loadPubspec() async => loadYaml(await File(pathToYaml).readAsString());

void main() async {
  var pubspec = await loadPubspec();
  print(pubspec['version'].toString().split('+')[0]);
}

You can run it from the project root folder:

dart run scripts/get_version_name.dart

I am currently developing an application which is currently in beta mode. Due to this, I would like to show them what version they are on. For example, "v1.0b10 - iOS". So far, I have got this code: Text("Build: V1.0b10 - " + (Platform.isIOS ? "iOS" : "Android")) . How would I be able to get the build version and number within flutter?

In Flutter mobile applications the version number is in pubspec.yaml file. like below:

version: 1.0.0+1

To get the version name and code, add the package_info dependency into pubspec.yaml file, like below:

dependencies:
  package_info: ^0.4.0+16

And

import 'package:package_info/package_info.dart'; // import the package_info

Future<void> _initPackageInfo() async {
    final _packageInfo = await PackageInfo.fromPlatform();
    setState(() {
          String AppName = _packageInfo.appName;
          String PackageName = _packageInfo.packageName;
          String AppVersion = _packageInfo.version;
          String BuildNumber = _packageInfo.buildNumber;
          String BuildSignature = _packageInfo.buildSignature;
    });
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM