diff --git a/frontend/mining-app/lib/presentation/pages/profile/profile_page.dart b/frontend/mining-app/lib/presentation/pages/profile/profile_page.dart index a15990db..35ff5041 100644 --- a/frontend/mining-app/lib/presentation/pages/profile/profile_page.dart +++ b/frontend/mining-app/lib/presentation/pages/profile/profile_page.dart @@ -15,6 +15,32 @@ class ProfilePage extends ConsumerWidget { static const Color _green = Color(0xFF10B981); static const Color _red = Color(0xFFEF4444); + // 浅色模式色彩 + static const Color _lightDarkText = Color(0xFF1F2937); + static const Color _lightGrayText = Color(0xFF6B7280); + static const Color _lightLightGray = Color(0xFF9CA3AF); + static const Color _lightBgGray = Color(0xFFF3F4F6); + static const Color _lightCardBg = Colors.white; + + // 深色模式色彩 + static const Color _darkDarkText = Color(0xFFE5E7EB); + static const Color _darkGrayText = Color(0xFF9CA3AF); + static const Color _darkLightGray = Color(0xFF6B7280); + static const Color _darkBgGray = Color(0xFF111827); + static const Color _darkCardBg = Color(0xFF1F2937); + + /// 根据当前主题获取颜色 + static Color _darkText(BuildContext context) => + Theme.of(context).brightness == Brightness.dark ? _darkDarkText : _lightDarkText; + static Color _grayText(BuildContext context) => + Theme.of(context).brightness == Brightness.dark ? _darkGrayText : _lightGrayText; + static Color _lightGray(BuildContext context) => + Theme.of(context).brightness == Brightness.dark ? _darkLightGray : _lightLightGray; + static Color _bgGray(BuildContext context) => + Theme.of(context).brightness == Brightness.dark ? _darkBgGray : _lightBgGray; + static Color _cardBg(BuildContext context) => + Theme.of(context).brightness == Brightness.dark ? _darkCardBg : _lightCardBg; + // 预设头像颜色列表(与编辑页面保持一致) static const List _avatarColors = [ Color(0xFFFF6B00), // 橙色 @@ -31,13 +57,12 @@ class ProfilePage extends ConsumerWidget { Widget build(BuildContext context, WidgetRef ref) { final user = ref.watch(userNotifierProvider); final statsAsync = ref.watch(userStatsProvider); - final colorScheme = Theme.of(context).colorScheme; final isStatsLoading = statsAsync.isLoading; final stats = statsAsync.valueOrNull; return Scaffold( - backgroundColor: colorScheme.surfaceContainerHighest, + backgroundColor: _bgGray(context), body: SafeArea( bottom: false, child: RefreshIndicator( @@ -50,36 +75,37 @@ class ProfilePage extends ConsumerWidget { child: Column( children: [ // 用户头部信息 - _buildUserHeader(context, user, colorScheme), + _buildUserHeader(context, user), const SizedBox(height: 16), // 统计数据行 - _buildStatsRow(context, stats, isStatsLoading, colorScheme), + _buildStatsRow(context, stats, isStatsLoading), const SizedBox(height: 16), // 账户设置 - _buildAccountSettings(context, user, colorScheme), + _buildAccountSettings(context, user), const SizedBox(height: 16), // 记录入口 - _buildRecordsSection(context, colorScheme), + _buildRecordsSection(context), const SizedBox(height: 16), - // 团队与收益(暂时隐藏,需要时取消注释) - // _buildTeamEarningsSection(context, colorScheme), - // const SizedBox(height: 16), + // 团队与收益 + _buildTeamEarningsSection(context), + + const SizedBox(height: 16), // 其他设置 - _buildOtherSettings(context, ref, colorScheme), + _buildOtherSettings(context, ref), const SizedBox(height: 24), // 退出登录 - _buildLogoutButton(context, ref, colorScheme), + _buildLogoutButton(context, ref), const SizedBox(height: 16), @@ -88,7 +114,7 @@ class ProfilePage extends ConsumerWidget { 'Version 1.0.0', style: TextStyle( fontSize: 12, - color: colorScheme.outline, + color: _lightGray(context), ), ), @@ -101,12 +127,12 @@ class ProfilePage extends ConsumerWidget { ); } - Widget _buildUserHeader(BuildContext context, UserState user, ColorScheme colorScheme) { + Widget _buildUserHeader(BuildContext context, UserState user) { final avatarColor = _avatarColors[user.avatarIndex % _avatarColors.length]; return Container( padding: const EdgeInsets.all(20), - color: colorScheme.surface, + color: _cardBg(context), child: Row( children: [ // 头像(可点击) @@ -156,7 +182,7 @@ class ProfilePage extends ConsumerWidget { style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, - color: colorScheme.onSurface, + color: _darkText(context), ), ), const SizedBox(width: 8), @@ -196,7 +222,7 @@ class ProfilePage extends ConsumerWidget { 'ID: ${user.phone}', style: TextStyle( fontSize: 14, - color: colorScheme.onSurfaceVariant, + color: _grayText(context), ), ), ], @@ -208,7 +234,7 @@ class ProfilePage extends ConsumerWidget { onPressed: () => context.push(Routes.editProfile), icon: Icon( Icons.edit_outlined, - color: colorScheme.onSurfaceVariant, + color: _grayText(context), ), ), ], @@ -216,46 +242,46 @@ class ProfilePage extends ConsumerWidget { ); } - Widget _buildStatsRow(BuildContext context, UserStats? stats, bool isLoading, ColorScheme colorScheme) { + Widget _buildStatsRow(BuildContext context, UserStats? stats, bool isLoading) { return Container( padding: const EdgeInsets.symmetric(vertical: 16), - color: colorScheme.surface, + color: _cardBg(context), child: Row( mainAxisAlignment: MainAxisAlignment.spaceEvenly, children: [ _buildStatItem( + context, '参与状态', stats?.hasAdopted == true ? '已参与' : '未参与', isLoading, - colorScheme, ), - _buildDivider(colorScheme), + _buildDivider(context), _buildStatItem( + context, '引荐人数', stats?.directReferralAdoptedCount.toString() ?? '0', isLoading, - colorScheme, ), - _buildDivider(colorScheme), + _buildDivider(context), _buildStatItem( + context, '团队下贡献值', stats?.unlockedLevelDepth.toString() ?? '0', isLoading, - colorScheme, ), - _buildDivider(colorScheme), + _buildDivider(context), _buildStatItem( + context, '团队上贡献值', '15', isLoading, - colorScheme, ), ], ), ); } - Widget _buildStatItem(String label, String value, bool isLoading, ColorScheme colorScheme) { + Widget _buildStatItem(BuildContext context, String label, String value, bool isLoading) { return Column( children: [ DataText( @@ -265,7 +291,7 @@ class ProfilePage extends ConsumerWidget { style: TextStyle( fontSize: 20, fontWeight: FontWeight.bold, - color: colorScheme.onSurface, + color: _darkText(context), ), ), const SizedBox(height: 4), @@ -273,26 +299,26 @@ class ProfilePage extends ConsumerWidget { label, style: TextStyle( fontSize: 12, - color: colorScheme.onSurfaceVariant, + color: _grayText(context), ), ), ], ); } - Widget _buildDivider(ColorScheme colorScheme) { + Widget _buildDivider(BuildContext context) { return Container( width: 1, height: 30, - color: colorScheme.outlineVariant, + color: _bgGray(context), ); } - Widget _buildAccountSettings(BuildContext context, UserState user, ColorScheme colorScheme) { + Widget _buildAccountSettings(BuildContext context, UserState user) { return Container( margin: const EdgeInsets.symmetric(horizontal: 16), decoration: BoxDecoration( - color: colorScheme.surface, + color: _cardBg(context), borderRadius: BorderRadius.circular(12), ), child: Column( @@ -305,16 +331,16 @@ class ProfilePage extends ConsumerWidget { style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, - color: colorScheme.onSurface, + color: _darkText(context), ), ), ), _buildSettingItem( + context: context, icon: Icons.security, label: '账户安全', onTap: () => context.push(Routes.changePassword), showDivider: false, - colorScheme: colorScheme, ), ], ), @@ -322,22 +348,22 @@ class ProfilePage extends ConsumerWidget { } Widget _buildSettingItem({ + required BuildContext context, required IconData icon, required String label, Widget? trailing, required VoidCallback onTap, bool showDivider = true, - required ColorScheme colorScheme, }) { return Column( children: [ ListTile( - leading: Icon(icon, color: colorScheme.onSurfaceVariant, size: 22), + leading: Icon(icon, color: _grayText(context), size: 22), title: Text( label, style: TextStyle( fontSize: 14, - color: colorScheme.onSurface, + color: _darkText(context), ), ), trailing: Row( @@ -345,7 +371,7 @@ class ProfilePage extends ConsumerWidget { children: [ if (trailing != null) trailing, if (trailing != null) const SizedBox(width: 8), - Icon(Icons.chevron_right, color: colorScheme.outline, size: 20), + Icon(Icons.chevron_right, color: _lightGray(context), size: 20), ], ), onTap: onTap, @@ -356,12 +382,12 @@ class ProfilePage extends ConsumerWidget { ); } - Widget _buildRecordsSection(BuildContext context, ColorScheme colorScheme) { + Widget _buildRecordsSection(BuildContext context) { return Container( margin: const EdgeInsets.symmetric(horizontal: 16), padding: const EdgeInsets.all(16), decoration: BoxDecoration( - color: colorScheme.surface, + color: _cardBg(context), borderRadius: BorderRadius.circular(12), ), child: Column( @@ -372,7 +398,7 @@ class ProfilePage extends ConsumerWidget { style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, - color: colorScheme.onSurface, + color: _darkText(context), ), ), const SizedBox(height: 16), @@ -380,22 +406,22 @@ class ProfilePage extends ConsumerWidget { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ _buildRecordIcon( + context: context, icon: Icons.eco, label: '参与记录', onTap: () => context.push(Routes.plantingRecords), - colorScheme: colorScheme, ), _buildRecordIcon( + context: context, icon: Icons.assignment, label: '分配记录', onTap: () => context.push(Routes.miningRecords), - colorScheme: colorScheme, ), _buildRecordIcon( + context: context, icon: Icons.receipt_long, label: '交易记录', onTap: () => context.push(Routes.tradingRecords), - colorScheme: colorScheme, ), ], ), @@ -405,10 +431,10 @@ class ProfilePage extends ConsumerWidget { } Widget _buildRecordIcon({ + required BuildContext context, required IconData icon, required String label, required VoidCallback onTap, - required ColorScheme colorScheme, }) { return GestureDetector( onTap: onTap, @@ -429,7 +455,7 @@ class ProfilePage extends ConsumerWidget { label, style: TextStyle( fontSize: 12, - color: colorScheme.onSurfaceVariant, + color: _grayText(context), ), ), ], @@ -437,11 +463,11 @@ class ProfilePage extends ConsumerWidget { ); } - Widget _buildTeamEarningsSection(BuildContext context, ColorScheme colorScheme) { + Widget _buildTeamEarningsSection(BuildContext context) { return Container( margin: const EdgeInsets.symmetric(horizontal: 16), decoration: BoxDecoration( - color: colorScheme.surface, + color: _cardBg(context), borderRadius: BorderRadius.circular(12), ), child: Column( @@ -454,30 +480,30 @@ class ProfilePage extends ConsumerWidget { style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, - color: colorScheme.onSurface, + color: _darkText(context), ), ), ), _buildSettingItem( + context: context, icon: Icons.people, label: '我的团队', onTap: () => context.push(Routes.myTeam), showDivider: false, - colorScheme: colorScheme, ), ], ), ); } - Widget _buildOtherSettings(BuildContext context, WidgetRef ref, ColorScheme colorScheme) { + Widget _buildOtherSettings(BuildContext context, WidgetRef ref) { final notificationsEnabled = ref.watch(notificationsEnabledProvider); final darkModeEnabled = ref.watch(darkModeEnabledProvider); return Container( margin: const EdgeInsets.symmetric(horizontal: 16), decoration: BoxDecoration( - color: colorScheme.surface, + color: _cardBg(context), borderRadius: BorderRadius.circular(12), ), child: Column( @@ -490,40 +516,40 @@ class ProfilePage extends ConsumerWidget { style: TextStyle( fontSize: 16, fontWeight: FontWeight.bold, - color: colorScheme.onSurface, + color: _darkText(context), ), ), ), _buildSwitchItem( + context: context, icon: Icons.notifications_outlined, label: '消息通知', value: notificationsEnabled, onChanged: (value) { ref.read(notificationsEnabledProvider.notifier).setEnabled(value); }, - colorScheme: colorScheme, ), _buildSwitchItem( + context: context, icon: Icons.dark_mode_outlined, label: '深色模式', value: darkModeEnabled, onChanged: (value) { ref.read(darkModeEnabledProvider.notifier).setEnabled(value); }, - colorScheme: colorScheme, ), _buildSettingItem( + context: context, icon: Icons.help_outline, label: '帮助中心', onTap: () => context.push(Routes.helpCenter), - colorScheme: colorScheme, ), _buildSettingItem( + context: context, icon: Icons.info_outline, label: '关于我们', onTap: () => context.push(Routes.about), showDivider: false, - colorScheme: colorScheme, ), ], ), @@ -531,21 +557,21 @@ class ProfilePage extends ConsumerWidget { } Widget _buildSwitchItem({ + required BuildContext context, required IconData icon, required String label, required bool value, required ValueChanged onChanged, - required ColorScheme colorScheme, }) { return Column( children: [ ListTile( - leading: Icon(icon, color: colorScheme.onSurfaceVariant, size: 22), + leading: Icon(icon, color: _grayText(context), size: 22), title: Text( label, style: TextStyle( fontSize: 14, - color: colorScheme.onSurface, + color: _darkText(context), ), ), trailing: Switch( @@ -560,7 +586,7 @@ class ProfilePage extends ConsumerWidget { ); } - Widget _buildLogoutButton(BuildContext context, WidgetRef ref, ColorScheme colorScheme) { + Widget _buildLogoutButton(BuildContext context, WidgetRef ref) { return Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: SizedBox( @@ -569,17 +595,17 @@ class ProfilePage extends ConsumerWidget { onPressed: () { showDialog( context: context, - builder: (context) => AlertDialog( + builder: (dialogContext) => AlertDialog( title: const Text('退出登录'), content: const Text('确定要退出登录吗?'), actions: [ TextButton( - onPressed: () => Navigator.pop(context), + onPressed: () => Navigator.pop(dialogContext), child: const Text('取消'), ), TextButton( onPressed: () { - Navigator.pop(context); + Navigator.pop(dialogContext); ref.read(userNotifierProvider.notifier).logout(); }, child: const Text( @@ -592,7 +618,7 @@ class ProfilePage extends ConsumerWidget { ); }, style: TextButton.styleFrom( - backgroundColor: colorScheme.surface, + backgroundColor: _cardBg(context), padding: const EdgeInsets.symmetric(vertical: 14), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12),