fix(frontend): 添加新账号时显示加载状态提示

- 添加 _isAddingAccount 状态变量
- 点击"添加新账号"时显示"正在准备..."加载提示
- 添加 try-catch 错误处理,失败时显示错误提示
- 防止重复点击

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-15 06:14:49 -08:00
parent 2a4efe0828
commit 3942cb405a
1 changed files with 33 additions and 14 deletions

View File

@ -20,6 +20,7 @@ class _AccountSwitchPageState extends ConsumerState<AccountSwitchPage> {
String? _currentAccountId;
bool _isLoading = true;
bool _isSwitching = false;
bool _isAddingAccount = false;
@override
void initState() {
@ -88,16 +89,34 @@ class _AccountSwitchPageState extends ConsumerState<AccountSwitchPage> {
}
Future<void> _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<AccountSwitchPage> {
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),
),