|
@@ -212,20 +212,47 @@ class _LocationPickerState extends State<LocationPicker> {
|
|
|
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);
|
|
|
- } 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);
|
|
if (mounted) setState(() => _locating = false);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void _showLocateError(BuildContext context) {
|
|
|
|
|
|
|
+ void _showLocateError(
|
|
|
|
|
+ BuildContext context, {
|
|
|
|
|
+ String? messageKey,
|
|
|
|
|
+ String? detail,
|
|
|
|
|
+ }) {
|
|
|
final l10n = AppLocalizations.of(context);
|
|
final l10n = AppLocalizations.of(context);
|
|
|
final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
final colors = Theme.of(context).extension<AppColorsExtension>()!;
|
|
|
|
|
+ final content = detail == null
|
|
|
|
|
+ ? l10n.get(messageKey ?? 'locateFailed')
|
|
|
|
|
+ : '${l10n.get(messageKey ?? 'locateFailed')}\n\n$detail';
|
|
|
showDialog(
|
|
showDialog(
|
|
|
context: context,
|
|
context: context,
|
|
|
useRootNavigator: true,
|
|
useRootNavigator: true,
|
|
|
builder: (ctx) => TDAlertDialog(
|
|
builder: (ctx) => TDAlertDialog(
|
|
|
- content: l10n.get('locateFailed'),
|
|
|
|
|
|
|
+ content: content,
|
|
|
|
|
+ // 带异常详情时限制高度,由 TDAlertDialog 自带的滚动处理长内容
|
|
|
|
|
+ contentMaxHeight: detail == null ? 0 : 240,
|
|
|
buttonStyle: TDDialogButtonStyle.text,
|
|
buttonStyle: TDDialogButtonStyle.text,
|
|
|
rightBtn: TDDialogButtonOptions(
|
|
rightBtn: TDDialogButtonOptions(
|
|
|
title: l10n.get('confirm'),
|
|
title: l10n.get('confirm'),
|