diff --git a/frontend/mobile-app/lib/features/account/presentation/pages/account_switch_page.dart b/frontend/mobile-app/lib/features/account/presentation/pages/account_switch_page.dart index a55f7c8e..db3031b5 100644 --- a/frontend/mobile-app/lib/features/account/presentation/pages/account_switch_page.dart +++ b/frontend/mobile-app/lib/features/account/presentation/pages/account_switch_page.dart @@ -20,6 +20,7 @@ class _AccountSwitchPageState extends ConsumerState { String? _currentAccountId; bool _isLoading = true; bool _isSwitching = false; + bool _isAddingAccount = false; @override void initState() { @@ -88,16 +89,34 @@ class _AccountSwitchPageState extends ConsumerState { } Future _addNewAccount() async { - // 保存当前账号数据 - final multiAccountService = ref.read(multiAccountServiceProvider); - await multiAccountService.saveCurrentAccountData(); + if (_isAddingAccount) return; - // 退出当前账号但保留数据 - await multiAccountService.logoutCurrentAccount(); + setState(() => _isAddingAccount = true); - // 跳转到向导页创建新账号 - if (mounted) { - context.go(RoutePaths.guide); + try { + final multiAccountService = ref.read(multiAccountServiceProvider); + + // 保存当前账号数据 + await multiAccountService.saveCurrentAccountData(); + + // 退出当前账号但保留数据 + await multiAccountService.logoutCurrentAccount(); + + // 跳转到向导页创建新账号 + if (mounted) { + context.go(RoutePaths.guide); + } + } catch (e) { + debugPrint('[AccountSwitchPage] 添加新账号失败: $e'); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('添加新账号失败: $e')), + ); + } + } finally { + if (mounted) { + setState(() => _isAddingAccount = false); + } } } @@ -179,18 +198,18 @@ class _AccountSwitchPageState extends ConsumerState { color: Color(0xFFD4AF37), ), ) - : _isSwitching - ? const Center( + : (_isSwitching || _isAddingAccount) + ? Center( child: Column( mainAxisAlignment: MainAxisAlignment.center, children: [ - CircularProgressIndicator( + const CircularProgressIndicator( color: Color(0xFFD4AF37), ), - SizedBox(height: 16), + const SizedBox(height: 16), Text( - '正在切换账号...', - style: TextStyle( + _isAddingAccount ? '正在准备...' : '正在切换账号...', + style: const TextStyle( fontSize: 14, color: Color(0xFF5D4037), ),