Flutter에서 new_version으로 업데이트 체크 시 Bad state: No element 오류 해결 (Android) 개발/Flutter2021. 12. 27. 11:57
업데이트 체크를 new_version 패키지로 잘 하고 있었는데 어느 순간 아래와 같이
Bad state: No element Exception이 발생하면서 정상 작동되지 않았다.
E/flutter ( 5782): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: Bad state: No element
E/flutter ( 5782): #0 ListMixin.firstWhere (dart:collection/list.dart:167:5)
E/flutter ( 5782): #1 NewVersion._getAndroidStoreVersion (package:new_version/new_version.dart:152:51)
확인 결과,
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.firstWhere(
(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,
);
}
위의 소스에서 보이듯이 new_version에서 Android는 https://play.google.com/store/apps/details 페이지로 접속해서
hAyfc 클래스를 가져와서 현재 스토어에 올라온 버전이 무엇인지 확인하는 과정이 있는데
플레이 스토어가 리뉴얼 하면서 그냥 https://play.google.com/store/apps/details?id=com.nhn.android.search로 접속하면
hAyfc 클래스가 없기 때문에 정상 작동은 커녕 오류를 발생하는 것으로 보였다.
이전과 같은 페이지를 보려면 다음과 같이 파라메터에 gl=us를 추가로 보내주면
(https://play.google.com/store/apps/details?id=com.nhn.android.search&gl=us)
hAyfc 클래스가 존재해서, 위 소스의 5번째 줄에 아래 처럼 코드를 수정하면 정상 동작하는 것을 확인하였다.
Uri.https("play.google.com", "/store/apps/details", {"id": "$id", "gl": "US"});
해당 소스의 위치는 나는 mac 환경이고 new_version 버전은 0.2.3을 사용하였기 때문에
/Users/${userId}/.pub-cache/hosted/pub.dartlang.org/new_version-0.2.3/lib/new_version.dart
여기에 저장되어 있었다.
'개발 > Flutter' 카테고리의 다른 글
Flutter에서 Flick 화면 만들기 (0) | 2022.08.03 |
---|---|
Flutter에서 TextField의 "붙여넣기" 도구 설명 이름을 한국어로 변경하는 방법 (0) | 2022.01.27 |
webview_flutter로 alert/confirm 띄우기 (iOS) (4) | 2021.11.11 |
webview_flutter로 file upload하기 (Android) (0) | 2021.11.09 |
Flutter에서 webview_flutter alert 안 보일 때 처리 법(toast로 표시) (0) | 2021.09.03 |