Преглед изворни кода

优化始发地目的地地图展示

chengc пре 1 дан
родитељ
комит
573d2a077a

+ 2 - 0
assets/i18n/en.json

@@ -124,6 +124,8 @@
     "locationPermissionTitle": "Location Permission",
     "locationPermissionMsg": "Location permission has been permanently denied. Please enable it in system settings.",
     "locateFailed": "Location failed, please check permission and network",
+    "locateServiceOff": "Location failed. Please enable location services",
+    "locateTimeout": "Location timed out. Please try again in an open area",
     "goToSettings": "Settings",
     "selectDateTime": "Select date & time",
     "selectDate": "Select date",

+ 2 - 0
assets/i18n/zh_CN.json

@@ -121,6 +121,8 @@
     "locationPermissionTitle": "定位权限",
     "locationPermissionMsg": "定位权限已被永久拒绝,请在系统设置中开启定位权限。",
     "locateFailed": "定位失败,请检查定位权限和网络",
+    "locateServiceOff": "定位失败,请开启系统位置服务",
+    "locateTimeout": "定位超时,请到开阔处重试",
     "goToSettings": "去设置",
     "selectDateTime": "选择日期时间",
     "selectDate": "选择日期",

+ 2 - 0
assets/i18n/zh_TW.json

@@ -124,6 +124,8 @@
     "locationPermissionTitle": "定位權限",
     "locationPermissionMsg": "定位權限已被永久拒絕,請在系統設定中開啟定位權限。",
     "locateFailed": "定位失敗,請檢查定位權限和網絡",
+    "locateServiceOff": "定位失敗,請開啟系統位置服務",
+    "locateTimeout": "定位超時,請到空曠處重試",
     "goToSettings": "去設定",
     "selectDateTime": "選擇日期時間",
     "selectDate": "選擇日期",

+ 31 - 4
lib/shared/widgets/location_picker.dart

@@ -212,20 +212,47 @@ class _LocationPickerState extends State<LocationPicker> {
       final p = LatLng(pos.latitude, pos.longitude);
       _mapCtrl.move(p, 16);
       _reverse(p);
-    } catch (_) {
-      if (mounted) _showLocateError(context);
+    } on LocationServiceDisabledException catch (e) {
+      // 系统位置服务(GPS)总开关关闭
+      if (mounted) {
+        _showLocateError(
+          context,
+          messageKey: 'locateServiceOff',
+          detail: e.toString(),
+        );
+      }
+    } on TimeoutException catch (e) {
+      // 定位超时(GPS 冷启动/室内等场景)
+      if (mounted) {
+        _showLocateError(
+          context,
+          messageKey: 'locateTimeout',
+          detail: e.toString(),
+        );
+      }
+    } catch (e) {
+      if (mounted) _showLocateError(context, detail: e.toString());
     }
     if (mounted) setState(() => _locating = false);
   }
 
-  void _showLocateError(BuildContext context) {
+  void _showLocateError(
+    BuildContext context, {
+    String? messageKey,
+    String? detail,
+  }) {
     final l10n = AppLocalizations.of(context);
     final colors = Theme.of(context).extension<AppColorsExtension>()!;
+    final content = detail == null
+        ? l10n.get(messageKey ?? 'locateFailed')
+        : '${l10n.get(messageKey ?? 'locateFailed')}\n\n$detail';
     showDialog(
       context: context,
       useRootNavigator: true,
       builder: (ctx) => TDAlertDialog(
-        content: l10n.get('locateFailed'),
+        content: content,
+        // 带异常详情时限制高度,由 TDAlertDialog 自带的滚动处理长内容
+        contentMaxHeight: detail == null ? 0 : 240,
         buttonStyle: TDDialogButtonStyle.text,
         rightBtn: TDDialogButtonOptions(
           title: l10n.get('confirm'),

+ 5 - 1
lib/shared/widgets/trip_route_card.dart

@@ -29,7 +29,9 @@ class TripRouteCard extends StatelessWidget {
       destLat != null &&
       destLng != null &&
       (originLat! != 0 || originLng! != 0) &&
-      (destLat! != 0 || destLng! != 0);
+      (destLat! != 0 || destLng! != 0) &&
+      // 起终点重合会使 flutter_map 计算出 Infinity/NaN zoom 而崩溃(瓦片层 round 报错),隐藏地图
+      (originLat != destLat || originLng != destLng);
 
   LatLng get _origin => LatLng(originLat!, originLng!);
   LatLng get _dest => LatLng(destLat!, destLng!);
@@ -153,6 +155,8 @@ class TripRouteCard extends StatelessWidget {
           initialCameraFit: CameraFit.bounds(
             bounds: LatLngBounds.fromPoints([_origin, _dest]),
             padding: const EdgeInsets.all(40),
+            // 高德瓦片最大 18 级:两点极近时 fit 出的 zoom 超限会导致瓦片 404,整图空白
+            maxZoom: 18,
           ),
         ),
         children: [