未经手的例外:不良状态:新版本软件包中没有元素new_version.dart

发布于 2025-02-11 03:27:21 字数 2402 浏览 1 评论 0原文

我第一次将应用程序放在Play商店中时,它具有升级功能,还可以正确显示升级对话框,但是现在它给了我以下错误。

 [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>

在此,我使用了new_version软件包0.2.3,这是我的代码,

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);
 }

我在new_version.dart lib文件中遇到了此错误

  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,
);

} 但是我得到了上述错误。我也更改了版本软件包,但不起作用。我有同样的错误。

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文