未经手的例外:不良状态:新版本软件包中没有元素new_version.dart
我第一次将应用程序放在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论