From 3644c04521a3bd09028908dcb73b42b58cd5f68b Mon Sep 17 00:00:00 2001 From: hailin Date: Thu, 11 Dec 2025 04:08:57 -0800 Subject: [PATCH] fix(mobile): auto-show confirm dialog when planting location is saved MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When user has previously saved province/city selection: - Automatically show confirm dialog on page load - Skip the 5-second countdown timer - Hide countdown text in dialog when skipCountdown is true - User can directly confirm and proceed with planting 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- .../pages/planting_location_page.dart | 21 ++++++++++++++++++- .../widgets/planting_confirm_dialog.dart | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart b/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart index 945b86fa..c9f6e985 100644 --- a/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart +++ b/frontend/mobile-app/lib/features/planting/presentation/pages/planting_location_page.dart @@ -65,7 +65,10 @@ class _PlantingLocationPageState extends ConsumerState { @override void initState() { super.initState(); - _loadSavedLocation(); + // 使用 WidgetsBinding 确保在 build 完成后执行 + WidgetsBinding.instance.addPostFrameCallback((_) { + _loadSavedLocation(); + }); } /// 从本地存储加载保存的省市 @@ -87,12 +90,28 @@ class _PlantingLocationPageState extends ConsumerState { _hasSavedLocation = true; }); debugPrint('[PlantingLocationPage] 已加载保存的省市: $provinceName · $cityName'); + + // 如果有保存的省市,直接弹出确认弹窗(跳过倒计时) + _showConfirmDialogDirectly(); } } catch (e) { debugPrint('[PlantingLocationPage] 加载省市失败: $e'); } } + /// 直接显示确认弹窗(用于已保存省市的情况) + Future _showConfirmDialogDirectly() async { + if (!mounted) return; + + await PlantingConfirmDialog.show( + context: context, + province: _selectedProvinceName!, + city: _selectedCityName!, + skipCountdown: true, // 跳过倒计时 + onConfirm: _submitPlanting, + ); + } + /// 保存省市到本地存储 Future _saveLocation() async { if (_selectedProvinceName == null || _selectedProvinceCode == null || diff --git a/frontend/mobile-app/lib/features/planting/presentation/widgets/planting_confirm_dialog.dart b/frontend/mobile-app/lib/features/planting/presentation/widgets/planting_confirm_dialog.dart index 1ce6966e..38ce80b6 100644 --- a/frontend/mobile-app/lib/features/planting/presentation/widgets/planting_confirm_dialog.dart +++ b/frontend/mobile-app/lib/features/planting/presentation/widgets/planting_confirm_dialog.dart @@ -264,6 +264,11 @@ class _PlantingConfirmDialogState extends State { /// 构建倒计时文字 Widget _buildCountdownText() { + // 如果跳过倒计时,不显示倒计时文字 + if (widget.skipCountdown) { + return const SizedBox(height: 16); + } + return Padding( padding: const EdgeInsets.symmetric(vertical: 16), child: Text(