0

I try to get the version of my app and the value is empty from PackageInfo. Please help!

PackageInfo packageInfo =
   await PackageInfo.fromPlatform();
print('package info: $packageInfo');

And I try to print PackageInfo in terminal:

PackageInfo(appName: MyApp, buildNumber: 3, version: )

As you see is the version from response empty... I have also tried:

Future getVersion() async {
    PackageInfo.fromPlatform().then((PackageInfo packageInfo) {
      setState(() {
        appName = packageInfo.appName;
        version = packageInfo.version;
        print('version: $version');
      });
    });
  }
Robban13
  • 21
  • 3

1 Answers1

0
import 'package:package_info_plus/package_info_plus.dart';

...

// Be sure to add this line if `PackageInfo.fromPlatform()` is called before runApp()
WidgetsFlutterBinding.ensureInitialized();

...

PackageInfo packageInfo = await PackageInfo.fromPlatform();

String appName = packageInfo.appName;
String packageName = packageInfo.packageName;
String version = packageInfo.version;
String buildNumber = packageInfo.buildNumber;
Rahul Kushwaha
  • 5,473
  • 3
  • 26
  • 30