242 lines
7.2 KiB
Dart
242 lines
7.2 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../../../core/constants/app_colors.dart';
|
|
import '../../../providers/auth_provider.dart';
|
|
|
|
/// 我的页面
|
|
class MinePage extends StatefulWidget {
|
|
const MinePage({super.key});
|
|
|
|
@override
|
|
State<MinePage> createState() => _MinePageState();
|
|
}
|
|
|
|
class _MinePageState extends State<MinePage> with AutomaticKeepAliveClientMixin {
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
return Scaffold(
|
|
backgroundColor: AppColors.background,
|
|
body: Consumer<AuthProvider>(
|
|
builder: (context, auth, _) {
|
|
final user = auth.user;
|
|
return SingleChildScrollView(
|
|
padding: const EdgeInsets.all(16),
|
|
child: Column(
|
|
children: [
|
|
_buildUserCard(user),
|
|
const SizedBox(height: 16),
|
|
_buildMenuList(context, auth),
|
|
const SizedBox(height: 24),
|
|
_buildLogoutButton(context, auth),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildUserCard(user) {
|
|
return Container(
|
|
padding: const EdgeInsets.all(20),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardBackground,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Row(
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 32,
|
|
backgroundColor: AppColors.primary.withOpacity(0.2),
|
|
child: Text(
|
|
user?.avatarText ?? 'U',
|
|
style: const TextStyle(
|
|
fontSize: 24,
|
|
color: AppColors.primary,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 16),
|
|
Expanded(
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
user?.username ?? '未登录',
|
|
style: const TextStyle(
|
|
fontSize: 20,
|
|
fontWeight: FontWeight.bold,
|
|
color: AppColors.textPrimary,
|
|
),
|
|
),
|
|
const SizedBox(height: 4),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primary.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: Text(
|
|
'普通用户',
|
|
style: const TextStyle(
|
|
fontSize: 12,
|
|
color: AppColors.primary,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
const Icon(Icons.chevron_right, color: AppColors.textSecondary),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMenuList(BuildContext context, AuthProvider auth) {
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
color: AppColors.cardBackground,
|
|
borderRadius: BorderRadius.circular(16),
|
|
),
|
|
child: Column(
|
|
children: [
|
|
_buildMenuItem(Icons.verified_user, '实名认证', () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('功能开发中')),
|
|
);
|
|
}),
|
|
const Divider(color: AppColors.border, height: 1),
|
|
_buildMenuItem(Icons.security, '安全设置', () {
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
const SnackBar(content: Text('功能开发中')));
|
|
}),
|
|
const Divider(color: AppColors.border, height: 1),
|
|
_buildMenuItem(Icons.info_outline, '关于我们', () {
|
|
showAboutDialog(context);
|
|
}),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildMenuItem(IconData icon, String title, VoidCallback onTap) {
|
|
return ListTile(
|
|
leading: Icon(icon, color: AppColors.primary),
|
|
title: Text(
|
|
title,
|
|
style: const TextStyle(color: AppColors.textPrimary),
|
|
),
|
|
trailing: const Icon(Icons.chevron_right, color: AppColors.textSecondary),
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
|
|
Widget _buildLogoutButton(BuildContext context, AuthProvider auth) {
|
|
return Container(
|
|
width: double.infinity,
|
|
height: 48,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.error.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: TextButton(
|
|
onPressed: () => _showLogoutDialog(context, auth),
|
|
child: const Text(
|
|
'退出登录',
|
|
style: TextStyle(
|
|
color: AppColors.error,
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
void _showLogoutDialog(BuildContext context, AuthProvider auth) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.cardBackground,
|
|
title: const Text('确认退出', style: TextStyle(color: AppColors.textPrimary)),
|
|
content: const Text(
|
|
'确定要退出登录吗?',
|
|
style: TextStyle(color: AppColors.textSecondary),
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('取消'),
|
|
),
|
|
ElevatedButton(
|
|
style: ElevatedButton.styleFrom(
|
|
backgroundColor: AppColors.error,
|
|
),
|
|
onPressed: () async {
|
|
Navigator.pop(context);
|
|
await auth.logout();
|
|
if (context.mounted) {
|
|
Navigator.pushReplacementNamed(context, '/login');
|
|
}
|
|
},
|
|
child: const Text('退出'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void showAboutDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (context) => AlertDialog(
|
|
backgroundColor: AppColors.cardBackground,
|
|
title: Row(
|
|
children: [
|
|
Container(
|
|
width: 40,
|
|
height: 40,
|
|
decoration: BoxDecoration(
|
|
color: AppColors.primary.withOpacity(0.2),
|
|
borderRadius: BorderRadius.circular(20),
|
|
),
|
|
child: const Center(
|
|
child: Text('₿', style: TextStyle(fontSize: 20, color: AppColors.primary)),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
const Text('模拟所', style: TextStyle(color: AppColors.textPrimary)),
|
|
],
|
|
),
|
|
content: const Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
'虚拟货币模拟交易平台',
|
|
style: TextStyle(color: AppColors.textSecondary),
|
|
),
|
|
SizedBox(height: 16),
|
|
Text(
|
|
'版本: 1.0.0',
|
|
style: TextStyle(color: AppColors.textHint, fontSize: 12),
|
|
),
|
|
],
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.pop(context),
|
|
child: const Text('确定'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|