Unhandled Exception: Bad state: No element in new version package new_version.dart

Viewed 193

The first time I put the app on the Play Store, it was running with upgrade functionality and also display the upgrade dialog properly but now it is giving me the following error.

 [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: Bad state: No element
ListMixin.firstWhere (dart:collection/list.dart:167:5)
NewVersion._getAndroidStoreVersion (package:new_version/new_version.dart:152:51)
<asynchronous suspension>

In this, I have used new_version package 0.2.3 and this is my code

void _checkVersion() async {
final newVersion = NewVersion(
androidId: "com.abc.pqr",
);
final status = await newVersion.getVersionStatus();

print("localVersion==> ${status.localVersion}");
print("localVersion==> ${status.storeVersion}");
status.localVersion!=status.storeVersion?

newVersion.showUpdateDialog(
context: context,
versionStatus: status,
dialogTitle: "UPDATE!!!",
dismissButtonText: "Skip",
dialogText: "Please update the abc app from " + "${status.localVersion}" + " to " 
+ "${status.storeVersion}",
dismissAction: () {
Navigator.pop(context);
},
updateButtonText: "Lets update",
):Container();

 print("DEVICE : " + status.localVersion);
  print("STORE : " + status.storeVersion);
 }

I got this error in new_version.dart lib file

  Future<VersionStatus?> _getAndroidStoreVersion(
  PackageInfo packageInfo) async {
final id = androidId ?? packageInfo.packageName;
final uri =
    Uri.https("play.google.com", "/store/apps/details", {"id": "$id"});
final response = await http.get(uri);
if (response.statusCode != 200) {
  debugPrint('Can\'t find an app in the Play Store with the id: $id');
  return null;
}
final document = parse(response.body);

final additionalInfoElements = document.getElementsByClassName('hAyfc');
final versionElement = additionalInfoElements.firstWhereOrNull(
  (elm) => elm.querySelector('.BgcNfc')!.text == 'Current Version',
);
final storeVersion = versionElement.querySelector('.htlgb')!.text;

final sectionElements = document.getElementsByClassName('W4P4ne');
final releaseNotesElement = sectionElements.firstWhereOrNull(
  (elm) => elm.querySelector('.wSaTQd')!.text == 'What\'s New',
);
final releaseNotes = releaseNotesElement
    ?.querySelector('.PHBdkd')
    ?.querySelector('.DWPxHb')
    ?.text;

return VersionStatus._(
  localVersion: packageInfo.version,
  storeVersion: storeVersion,
  appStoreLink: uri.toString(),
  releaseNotes: releaseNotes,
);

} but I got the above error. I changed the version package also but not working. I got the same error.pls help

0 Answers
Related