feat(profile): 添加退出登录和切换账号功能

- 在版本信息栏添加构建模式显示(Debug/Release/Profile)
- 在版本信息栏下方添加切换账号按钮(暂显示即将上线提示)
- 在版本信息栏下方添加退出登录按钮(带确认对话框)
- 退出登录后清除本地数据并跳转到向导页

🤖 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 02:16:36 -08:00
parent 09e66cef10
commit 04644ea3f8
1 changed files with 213 additions and 54 deletions

View File

@ -1,5 +1,6 @@
import 'dart:io';
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
@ -802,66 +803,71 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
return Container(
height: 48,
padding: const EdgeInsets.only(top: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
child: Stack(
alignment: Alignment.center,
children: [
//
const Text(
'我的',
style: TextStyle(
fontSize: 20,
fontFamily: 'Inter',
fontWeight: FontWeight.w700,
color: Color(0xFF5D4037),
//
const Center(
child: Text(
'我的',
style: TextStyle(
fontSize: 20,
fontFamily: 'Inter',
fontWeight: FontWeight.w700,
color: Color(0xFF5D4037),
),
),
),
//
GestureDetector(
onTap: _goToNotifications,
child: Container(
width: 40,
height: 40,
alignment: Alignment.center,
child: Stack(
clipBehavior: Clip.none,
children: [
const Icon(
Icons.notifications_outlined,
size: 26,
color: Color(0xFF5D4037),
),
//
if (_unreadNotificationCount > 0)
Positioned(
top: -4,
right: -4,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
vertical: 2,
),
decoration: BoxDecoration(
color: const Color(0xFFD4AF37),
borderRadius: BorderRadius.circular(10),
),
constraints: const BoxConstraints(
minWidth: 18,
minHeight: 18,
),
child: Text(
_unreadNotificationCount > 99
? '99+'
: _unreadNotificationCount.toString(),
style: const TextStyle(
fontSize: 10,
fontWeight: FontWeight.w600,
color: Colors.white,
//
Positioned(
right: 0,
child: GestureDetector(
onTap: _goToNotifications,
child: Container(
width: 40,
height: 40,
alignment: Alignment.center,
child: Stack(
clipBehavior: Clip.none,
children: [
const Icon(
Icons.notifications_outlined,
size: 26,
color: Color(0xFF5D4037),
),
//
if (_unreadNotificationCount > 0)
Positioned(
top: -4,
right: -4,
child: Container(
padding: const EdgeInsets.symmetric(
horizontal: 5,
vertical: 2,
),
decoration: BoxDecoration(
color: const Color(0xFFD4AF37),
borderRadius: BorderRadius.circular(10),
),
constraints: const BoxConstraints(
minWidth: 18,
minHeight: 18,
),
child: Text(
_unreadNotificationCount > 99
? '99+'
: _unreadNotificationCount.toString(),
style: const TextStyle(
fontSize: 10,
fontWeight: FontWeight.w600,
color: Colors.white,
),
textAlign: TextAlign.center,
),
textAlign: TextAlign.center,
),
),
),
],
],
),
),
),
),
@ -1309,6 +1315,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
const SizedBox(height: 16),
//
_buildAppVersionInfo(),
const SizedBox(height: 16),
//
_buildAccountActionButtons(),
],
),
);
@ -2711,6 +2720,8 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
const SizedBox(height: 8),
_buildVersionInfoRow('构建号', _buildNumber),
const SizedBox(height: 8),
_buildVersionInfoRow('构建模式', kReleaseMode ? 'Release' : (kDebugMode ? 'Debug' : 'Profile')),
const SizedBox(height: 8),
_buildVersionInfoRow('包名', _packageName),
const Divider(
height: 24,
@ -2771,4 +2782,152 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
],
);
}
/// 退
Widget _buildAccountActionButtons() {
return Column(
children: [
//
GestureDetector(
onTap: _onSwitchAccount,
child: Container(
width: double.infinity,
height: 48,
decoration: BoxDecoration(
color: const Color(0xFFFFF5E6),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: const Color(0x33D4AF37),
width: 1,
),
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.swap_horiz,
size: 20,
color: Color(0xFF8B5A2B),
),
SizedBox(width: 8),
Text(
'切换账号',
style: TextStyle(
fontSize: 15,
fontFamily: 'Inter',
fontWeight: FontWeight.w500,
height: 1.5,
color: Color(0xFF5D4037),
),
),
],
),
),
),
const SizedBox(height: 12),
// 退
GestureDetector(
onTap: _onLogout,
child: Container(
width: double.infinity,
height: 48,
decoration: BoxDecoration(
color: const Color(0xFFFFF5E6),
borderRadius: BorderRadius.circular(8),
border: Border.all(
color: const Color(0x33E57373),
width: 1,
),
),
child: const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(
Icons.logout,
size: 20,
color: Color(0xFFE57373),
),
SizedBox(width: 8),
Text(
'退出登录',
style: TextStyle(
fontSize: 15,
fontFamily: 'Inter',
fontWeight: FontWeight.w500,
height: 1.5,
color: Color(0xFFE57373),
),
),
],
),
),
),
const SizedBox(height: 32), //
],
);
}
///
void _onSwitchAccount() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('切换账号'),
content: const Text('多账号管理功能即将上线,敬请期待。'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('确定'),
),
],
),
);
}
/// 退
void _onLogout() {
showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('退出登录'),
content: const Text('确定要退出当前账号吗?\n\n退出后需要重新导入助记词才能恢复账号。'),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('取消'),
),
TextButton(
onPressed: () {
Navigator.of(context).pop();
_performLogout();
},
style: TextButton.styleFrom(
foregroundColor: const Color(0xFFE57373),
),
child: const Text('退出'),
),
],
),
);
}
/// 退
Future<void> _performLogout() async {
try {
final accountService = ref.read(accountServiceProvider);
//
await accountService.logout();
//
if (mounted) {
context.go(RoutePaths.guide);
}
} catch (e) {
debugPrint('[ProfilePage] 退出登录失败: $e');
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('退出登录失败: $e')),
);
}
}
}
}