|
@@ -6,7 +6,7 @@ import 'package:flutter_map/flutter_map.dart';
|
|
|
import 'package:latlong2/latlong.dart';
|
|
import 'package:latlong2/latlong.dart';
|
|
|
import 'package:geolocator/geolocator.dart';
|
|
import 'package:geolocator/geolocator.dart';
|
|
|
import 'package:http/http.dart' as http;
|
|
import 'package:http/http.dart' as http;
|
|
|
-import 'package:tdesign_flutter/tdesign_flutter.dart';
|
|
|
|
|
|
|
+import 'package:tdesign_flutter/tdesign_flutter.dart' hide Position;
|
|
|
import '../../core/theme/app_colors_extension.dart';
|
|
import '../../core/theme/app_colors_extension.dart';
|
|
|
import '../../core/i18n/app_localizations.dart';
|
|
import '../../core/i18n/app_localizations.dart';
|
|
|
|
|
|
|
@@ -204,11 +204,7 @@ class _LocationPickerState extends State<LocationPicker> {
|
|
|
}
|
|
}
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
- final pos = await Geolocator.getCurrentPosition(
|
|
|
|
|
- desiredAccuracy: LocationAccuracy.high,
|
|
|
|
|
- forceAndroidLocationManager: true,
|
|
|
|
|
- timeLimit: const Duration(seconds: 10),
|
|
|
|
|
- );
|
|
|
|
|
|
|
+ final pos = await _getPositionWithRetry();
|
|
|
final p = LatLng(pos.latitude, pos.longitude);
|
|
final p = LatLng(pos.latitude, pos.longitude);
|
|
|
_mapCtrl.move(p, 16);
|
|
_mapCtrl.move(p, 16);
|
|
|
_reverse(p);
|
|
_reverse(p);
|
|
@@ -236,29 +232,45 @@ class _LocationPickerState extends State<LocationPicker> {
|
|
|
if (mounted) setState(() => _locating = false);
|
|
if (mounted) setState(() => _locating = false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /// 获取当前位置:20 秒超时,超时自动重试一次(GPS 冷启动后第二次定位成功率更高)。
|
|
|
|
|
+ /// 重试仍超时则抛 [TimeoutException],由 _locate 弹超时提示。
|
|
|
|
|
+ Future<Position> _getPositionWithRetry() async {
|
|
|
|
|
+ const timeout = Duration(seconds: 20);
|
|
|
|
|
+ try {
|
|
|
|
|
+ return await Geolocator.getCurrentPosition(
|
|
|
|
|
+ desiredAccuracy: LocationAccuracy.high,
|
|
|
|
|
+ forceAndroidLocationManager: true,
|
|
|
|
|
+ timeLimit: timeout,
|
|
|
|
|
+ );
|
|
|
|
|
+ } on TimeoutException {
|
|
|
|
|
+ return Geolocator.getCurrentPosition(
|
|
|
|
|
+ desiredAccuracy: LocationAccuracy.high,
|
|
|
|
|
+ forceAndroidLocationManager: true,
|
|
|
|
|
+ timeLimit: timeout,
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void _showLocateError(
|
|
void _showLocateError(
|
|
|
BuildContext context, {
|
|
BuildContext context, {
|
|
|
String? messageKey,
|
|
String? messageKey,
|
|
|
String? detail,
|
|
String? detail,
|
|
|
}) {
|
|
}) {
|
|
|
final l10n = AppLocalizations.of(context);
|
|
final l10n = AppLocalizations.of(context);
|
|
|
- final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
|
|
final content = detail == null
|
|
final content = detail == null
|
|
|
? l10n.get(messageKey ?? 'locateFailed')
|
|
? l10n.get(messageKey ?? 'locateFailed')
|
|
|
: '${l10n.get(messageKey ?? 'locateFailed')}\n\n$detail';
|
|
: '${l10n.get(messageKey ?? 'locateFailed')}\n\n$detail';
|
|
|
showDialog(
|
|
showDialog(
|
|
|
context: context,
|
|
context: context,
|
|
|
useRootNavigator: true,
|
|
useRootNavigator: true,
|
|
|
- builder: (ctx) => TDAlertDialog(
|
|
|
|
|
|
|
+ // 单按钮确认框:TDConfirmDialog 天然只有一个按钮(TDAlertDialog 会自动补默认"取消")
|
|
|
|
|
+ builder: (ctx) => TDConfirmDialog(
|
|
|
content: content,
|
|
content: content,
|
|
|
- // 带异常详情时限制高度,由 TDAlertDialog 自带的滚动处理长内容
|
|
|
|
|
|
|
+ // 带异常详情时限制高度,由组件自带的滚动处理长内容
|
|
|
contentMaxHeight: detail == null ? 0 : 240,
|
|
contentMaxHeight: detail == null ? 0 : 240,
|
|
|
|
|
+ buttonText: l10n.get('confirm'),
|
|
|
buttonStyle: TDDialogButtonStyle.text,
|
|
buttonStyle: TDDialogButtonStyle.text,
|
|
|
- rightBtn: TDDialogButtonOptions(
|
|
|
|
|
- title: l10n.get('confirm'),
|
|
|
|
|
- titleColor: colors.primary,
|
|
|
|
|
- action: () => Navigator.pop(ctx),
|
|
|
|
|
- ),
|
|
|
|
|
|
|
+ action: () => Navigator.pop(ctx),
|
|
|
),
|
|
),
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|