fetchAndroid function

Future<AppVersionData> fetchAndroid({
  1. PackageInfo? packageInfo,
  2. String? playStoreId,
  3. String? country,
})

Implementation

Future<AppVersionData> fetchAndroid(
    {PackageInfo? packageInfo, String? playStoreId, String? country}) async {
  playStoreId = playStoreId ?? packageInfo?.packageName;
  final parameters = {"id": playStoreId, "hl": country};
  var uri = Uri.https(playStoreAuthority, playStoreUndecodedPath, parameters);
  final response =
      await http.get(uri, headers: headers).catchError((e) => throw e);
  if (response.statusCode == 200) {
    final versionMatch =
        RegExp(r',\[\[\["([0-9,\.]*)"]],').firstMatch(response.body);
    if (versionMatch != null) {
      return AppVersionData(
          storeVersion: versionMatch.group(1),
          storeUrl: uri.toString(),
          localVersion: packageInfo?.version,
          targetPlatform: TargetPlatform.android,
          );
    } else {
      throw " Aplication not found in Play Store, verify your app id. ";
    }
  } else {
    throw " Aplication not found in Play Store, verify your app id. ";
  }
}