[Regression]: placemarkFromCoordinates never completes on Android 13+ when the geocoder reports an error
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 84/100
Hướng nghiên cứu
Issue chỉ đến _GeocodeListenerWrapper trong geocoding_android/lib/src/geocoding_android.dart và mô tả việc thiếu xử lý lỗi trong callback onError của nó. Hãy đọc wrapper đó và luồng hoàn tất hiện có cho onGeocode, sau đó kiểm tra hành vi của listener geocoder Android được mô tả trong issue. Công việc hoàn tất khi phản hồi onError hoàn tất Future với lỗi thay vì để Future ở trạng thái chờ.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Is there an existing issue for this?
- I have searched the existing issues.
Please select affected platform(s)
- Android
- iOS
Old behavior
With geocoding 4.0.0 (geocoding_android 4.0.1), when the platform geocoder failed on Android 13+ (API 33+), Geocoder.GeocodeListener.onError was forwarded to Dart and placemarkFromCoordinates threw a PlatformException with code IO_ERROR, so the caller could handle it:
// geocoding_android 4.0.1, MethodCallHandlerImpl.java
@Override
public void onError(@Nullable String errorMessage) {
result.error(
"IO_ERROR",
errorMessage != null ? errorMessage : "Unknown error occurred",
null);
}
On an Android 13 (API 33) emulator in airplane mode, the call fails within a few seconds with:
PlatformException(IO_ERROR, kjez: UNAVAILABLE, null, null)
Current behavior
With geocoding 5.0.1 (geocoding_android 5.1.0), the same call never completes and never throws. In the sample below it only ends because of the 30 s timeout.
_GeocodeListenerWrapper registers an empty onError handler, and its Completer is only completed in onGeocode:
_listener = geocoderProxy.newGeocodeListener(
onError: (GeocodeListener listener, String? error) {},
onGeocode: _onGeocode);
The native side forwards onError to Dart (GeocodeListenerProxyApi.kt), but the Dart side drops it, so any caller awaiting the Future without its own timeout waits forever.
Below API 33 the plugin uses the synchronous getFromLocation / getFromLocationName, which still throw on failure, so only Android 13+ is affected.
This is not limited to being offline. Right after the network came back, the platform geocoder also reported its own timeout through onError (4.0.1 surfaced it as PlatformException(IO_ERROR, java.util.concurrent.TimeoutException: Waited 5 seconds ... [tag=[ReverseGeocode]] ...)), which 5.x would drop in the same way.
Steps to reproduce
- Use an Android 13+ device or emulator (tested on an API 33 emulator with Google Play services).
- Turn on airplane mode.
- Launch the code sample. It calls
placemarkFromCoordinateson start, with slightly different coordinates each launch so that a cached result is not returned. - geocoding 4.0.0:
Error: PlatformException(IO_ERROR, kjez: UNAVAILABLE, null, null)after a few seconds.
geocoding 5.0.1:Never completed (timed out after 30 s). - With airplane mode off, both versions return placemarks.
Code sample
Code sample (geocoding 5.0.1)
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:geocoding/geocoding.dart';
void main() => runApp(const MaterialApp(home: Repro()));
class Repro extends StatefulWidget {
const Repro({super.key});
@override
State<Repro> createState() => _ReproState();
}
class _ReproState extends State<Repro> {
String _result = 'Waiting...';
@override
void initState() {
super.initState();
_geocode();
}
Future<void> _geocode() async {
// Use different coordinates on each launch to avoid a cached result.
final lat = 35.0 + (DateTime.now().millisecondsSinceEpoch % 100000) / 100000;
String result;
try {
final placemarks = await Geocoding()
.placemarkFromCoordinates(lat, 139.7671)
.timeout(const Duration(seconds: 30));
result = 'Result: ${placemarks.length} placemark(s)';
} on TimeoutException {
result = 'Never completed (timed out after 30 s)';
} on Exception catch (e) {
result = 'Error: $e';
}
debugPrint(result);
setState(() => _result = result);
}
@override
Widget build(BuildContext context) =>
Scaffold(body: Center(child: Text(_result)));
}
For geocoding 4.0.0, replace Geocoding().placemarkFromCoordinates( with the top-level placemarkFromCoordinates(.
Screenshots or video
Screenshots or video demonstration
Results on an Android 13 (API 33) emulator, two runs per version:
| Airplane mode on | Airplane mode off | |
|---|---|---|
| geocoding 4.0.0 / geocoding_android 4.0.1 | PlatformException(IO_ERROR, kjez: UNAVAILABLE, null, null) after 6–9 s |
5 placemarks |
| geocoding 5.0.1 / geocoding_android 5.1.0 | Never completed (30 s timeout) | 5 placemarks |
Current version
geocoding 5.0.1 (geocoding_android 5.1.0). The empty handler is also on main.
Last version without regression
geocoding 4.0.0 (geocoding_android 4.0.1)
A possible fix, matching the old behavior:
_listener = geocoderProxy.newGeocodeListener(
onError: (GeocodeListener listener, String? error) {
_completer.completeError(PlatformException(
code: 'IO_ERROR',
message: error ?? 'Unknown error occurred',
));
},
onGeocode: _onGeocode);
Happy to open a PR with this change if that helps.
- Ngôn ngữ chính
- Dart
- Star
- 154
- Fork
- 94
- Merge trung bình
- 1 giờ 21 phút
- Pull request đã merge (30 ngày)
- 3
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của Baseflow/flutter-geocoding
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
Baseflow/flutter-geocoding#332 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[Bug]: `Geocoding(locale: ...)` has no effect – locale is not forwarded to `_fromPlatformCreationParams`Có thể làm lại được @AmrWalidi đã nhận 27 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
Baseflow/flutter-geocoding#324 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 84/100
Baseflow/flutter-geocoding#311 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Baseflow/flutter-geocoding#309 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 49/100
Baseflow/flutter-geocoding#327 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của Baseflow/flutter-geocoding
Issue tương tự
-
feature
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
VeryGoodOpenSource/vgv-ai-flutter-plugin#219 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
Anxcye/anx-reader#1024 ·
-
[cloud_functions]: Apple platforms ignore custom domains passed as regionCó thể đã có người làm @ragavendranbala-TSL đã nhận hôm nay. Đang mởNeeds Attention platform: ios platform: macos plugin: functions type: bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
firebase/flutterfire#19015 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 4 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
RevenueCat/purchases-flutter#2048 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
hajisensai/Fushi#4543 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày