getAndroidAtStoreVersion method

Future<AppVersionStatus?> getAndroidAtStoreVersion(
  1. String applicationId
)

Implementation

Future<AppVersionStatus?> getAndroidAtStoreVersion(
    String applicationId) async {
  try {
    final url =
        'https://play.google.com/store/apps/details?id=$applicationId';
    final response = await http.get(Uri.parse(url));
    if (response.statusCode != 200) {
      // The app with application id: $applicationId was not found in play store
      return null;
    }
    final document = html.parse(response.body);
    final elements = document.getElementsByClassName('hAyfc');
    final versionElement = elements.firstWhere(
      (elm) => elm.querySelector('.BgcNfc')?.text == 'Current Version',
    );

    final versionStatus = AppVersionStatus(
        storeVersion: versionElement.querySelector('.htlgb')?.text ?? '',
        appStoreUrl: url,
        platform: 'android');

    return versionStatus;
  } catch (e) {
    return null;
  }
}