Leong
Leong

Reputation: 329

Flutter: How to get app latest version number from Google Play Store

I am working on a project that require me to compare the app version. I am currently using package_info_plus to get the current app version, but I still can't manage to get the latest version from the Play Store. Is there anyway to allow me to read the latest version number from the Play Store using my App ID?

Upvotes: 1

Views: 924

Answers (4)

Leong
Leong

Reputation: 329

I tried getting the app version from store with another package (new_version_plus) and it works:

final newVersion = NewVersionPlus();
var status = await newVersion.getVersionStatus();
var storeVersion = status?.storeVersion;

Upvotes: 1

Yaros
Yaros

Reputation: 84

Use the following function to scrape the version from the page listing:

Future<String> _checkPlayStore(String packageName) async {
  final uri =
      Uri.https("play.google.com", "/store/apps/details", {"id": packageName});
  late String latestVersion;
  final response = await http.get(uri);
  if (response.statusCode != 200) {
    throw HttpException(
        "Can't get the version number, check that the package name is correct.");
  } else {
    latestVersion =
        RegExp(r',\[\[\["([0-9,\.]*)"]],').firstMatch(response.body)!.group(1)!;
  }
  return latestVersion;
}

Upvotes: 0

Jojo YOLO
Jojo YOLO

Reputation: 66

You can use flutter_app_version_checker: ^0.3.2 for getting app verion name , version , is update available and many more . for more info visit https://pub.dev/packages/flutter_app_version_checker

  _checker.checkUpdate().then((value) {
    print(value.canUpdate); //return true if update is available
    print(value.currentVersion); //return current app version
    print(value.newVersion); //return the new app version
    print(value.appURL); //return the app url
    print(value.errorMessage); //return error message if found else it will return null
});

Upvotes: 1

Shoua Ul Qammar
Shoua Ul Qammar

Reputation: 233

i always add a Config API where i return an Object for Latest Version where one property defines its latest version and 2nd one defines is that require to update or not

API Response Looks like this

{ "latestVersion": "1.2.3", "isUpdateRequired": true }

Upvotes: 0

Related Questions