189 lines
5.2 KiB
Dart
189 lines
5.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import '../../../../core/theme/design_tokens.dart';
|
|
import '../../../../shared/widgets/page_header.dart' as widgets;
|
|
import '../../../auth/presentation/bloc/auth_bloc.dart';
|
|
import '../../../auth/presentation/bloc/auth_event.dart';
|
|
import '../../../auth/presentation/bloc/auth_state.dart';
|
|
|
|
class AccountScreen extends StatelessWidget {
|
|
const AccountScreen({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: AppColors.surfaceSecondary,
|
|
body: SafeArea(
|
|
child: Column(
|
|
children: [
|
|
_buildHeader(context),
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
padding: const EdgeInsets.all(20),
|
|
child: Column(
|
|
children: [
|
|
_buildMenuCard(context),
|
|
const SizedBox(height: 24),
|
|
_buildLogoutButton(context),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildHeader(BuildContext context) {
|
|
return SizedBox(
|
|
height: 64,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 20),
|
|
child: Row(
|
|
children: [
|
|
widgets.BackButton(),
|
|
const SizedBox(width: 12),
|
|
const Text(
|
|
'我的账户',
|
|
style: TextStyle(
|
|
fontSize: 17,
|
|
fontWeight: FontWeight.w600,
|
|
color: AppColors.slate900,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMenuCard(BuildContext context) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: AppColors.white,
|
|
borderRadius: BorderRadius.circular(16),
|
|
border: Border.all(color: AppColors.borderSecondary),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildMenuItem(
|
|
icon: Icons.edit,
|
|
title: '编辑资料',
|
|
onTap: () => context.push('/edit-profile'),
|
|
),
|
|
_buildDivider(),
|
|
_buildMenuItem(
|
|
icon: Icons.lock,
|
|
title: '修改密码',
|
|
onTap: () => context.push('/change-password'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMenuItem({
|
|
required IconData icon,
|
|
required String title,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
return GestureDetector(
|
|
onTap: onTap,
|
|
behavior: HitTestBehavior.opaque,
|
|
child: Container(
|
|
height: 56,
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
|
child: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Row(
|
|
children: [
|
|
Icon(icon, size: 20, color: AppColors.slate500),
|
|
const SizedBox(width: 12),
|
|
Text(
|
|
title,
|
|
style: const TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w500,
|
|
color: AppColors.slate900,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const Icon(
|
|
Icons.chevron_right,
|
|
size: 18,
|
|
color: AppColors.slate400,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDivider() {
|
|
return Container(
|
|
height: 1,
|
|
margin: const EdgeInsets.symmetric(horizontal: 16),
|
|
color: const Color(0xFFEEF2F7),
|
|
);
|
|
}
|
|
|
|
Widget _buildLogoutButton(BuildContext context) {
|
|
return GestureDetector(
|
|
onTap: () => _showLogoutDialog(context),
|
|
child: Container(
|
|
width: double.infinity,
|
|
height: 52,
|
|
decoration: BoxDecoration(
|
|
color: const Color(0xFFFEE2E2),
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(color: const Color(0xFFFECACA)),
|
|
),
|
|
child: const Center(
|
|
child: Text(
|
|
'退出登录',
|
|
style: TextStyle(
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
color: Color(0xFFDC2626),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showLogoutDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (dialogContext) => AlertDialog(
|
|
title: const Text('退出登录'),
|
|
content: const Text('确定要退出当前账户吗?'),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(dialogContext).pop(),
|
|
child: const Text('取消'),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
Navigator.of(dialogContext).pop();
|
|
final authBloc = context.read<AuthBloc>();
|
|
authBloc.add(AuthLoggedOut());
|
|
await authBloc.stream.firstWhere(
|
|
(state) => state is AuthUnauthenticated,
|
|
);
|
|
if (context.mounted) {
|
|
context.go('/');
|
|
}
|
|
},
|
|
child: const Text('退出', style: TextStyle(color: Color(0xFFDC2626))),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|