fetchIOS function

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

Implementation

Future<AppVersionData> fetchIOS(
    {PackageInfo? packageInfo, String? appleId, String? country}) async {
  appleId = appleId ?? packageInfo?.packageName;
  final parameters = {"id": appleId};
  var uri = Uri.https(appleStoreAuthority, '/$country/lookup', parameters);
  final response = await http.get(uri, headers: headers);
  if (response.statusCode == 200) {
    final jsonResult = json.decode(response.body);
    final List results = jsonResult['results'];
    if (results.isEmpty) {
      throw " Aplication not found in Apple Store, verify your app id. ";
    } else {
      return AppVersionData(
          storeVersion: jsonResult['results'].first['version'],
          storeUrl: jsonResult['results'].first['trackViewUrl'],
          localVersion: packageInfo?.version,
          targetPlatform: TargetPlatform.iOS);
    }
  } else {
    return throw " Aplication not found in Apple Store, verify your app id. ";
  }
}