import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:shadcn_ui/shadcn_ui.dart'; import '../../core/app_theme.dart'; import '../../core/navigation_provider.dart'; import '../../providers/auth_provider.dart'; import '../../widgets/app_menu_item.dart'; class ProfilePage extends ConsumerWidget { const ProfilePage({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final auth = ref.watch(authProvider); final user = auth.user; final theme = ShadTheme.of(context); return Scaffold( backgroundColor: theme.colorScheme.background, body: SafeArea(child: SingleChildScrollView( padding: const EdgeInsets.only(bottom: AppTheme.sXl), child: Column(children: [ // 用户头部卡片 Container( width: double.infinity, padding: const EdgeInsets.all(AppTheme.rXl), decoration: BoxDecoration( color: theme.colorScheme.card, borderRadius: const BorderRadius.only( bottomLeft: Radius.circular(AppTheme.rXl), bottomRight: Radius.circular(AppTheme.rXl), ), boxShadow: [AppTheme.shadowLight], ), child: InkWell( onTap: () => pushRoute(ref, 'healthArchive'), borderRadius: BorderRadius.circular(AppTheme.rSm), child: Padding( padding: const EdgeInsets.symmetric(vertical: AppTheme.sSm), child: Row(children: [ Stack(children: [ CircleAvatar( radius: 32, backgroundColor: AppTheme.primaryLight, backgroundImage: user?.avatarUrl != null ? NetworkImage(user!.avatarUrl!) : null, child: user?.avatarUrl == null ? const Icon(Icons.person, size: 36, color: AppTheme.primary) : null, ), Positioned( right: 0, bottom: 0, child: Container( width: 20, height: 20, decoration: BoxDecoration( color: AppTheme.primary, borderRadius: BorderRadius.circular(10), border: Border.all(color: theme.colorScheme.card, width: 2), ), child: const Icon(Icons.edit, size: 13, color: Colors.white), ), ), ]), const SizedBox(width: AppTheme.sLg), Expanded(child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ Text(user?.name ?? '未设置昵称', style: TextStyle(fontSize: 23, fontWeight: FontWeight.bold, color: theme.colorScheme.foreground)), const SizedBox(height: 4), Text(user?.phone ?? '', style: TextStyle(fontSize: 17, color: theme.colorScheme.mutedForeground)), ])), Icon(LucideIcons.chevronRight, size: 25, color: theme.colorScheme.mutedForeground), ]), ), ), ), const SizedBox(height: AppTheme.sMd), AppMenuItem(icon: LucideIcons.folderArchive, title: '健康档案', onTap: () => pushRoute(ref, 'healthArchive')), AppMenuItem(icon: LucideIcons.settings, title: '设置', onTap: () => pushRoute(ref, 'settings')), const SizedBox(height: 40), // 退出登录 GestureDetector( onTap: () => _logout(context, ref), child: Container( margin: const EdgeInsets.symmetric(horizontal: AppTheme.rXl), height: 50, alignment: Alignment.center, decoration: BoxDecoration( border: Border.all(color: theme.colorScheme.destructive.withAlpha(80)), borderRadius: BorderRadius.circular(AppTheme.rPill), ), child: Text('退出登录', style: TextStyle(fontSize: 19, color: theme.colorScheme.destructive, fontWeight: FontWeight.w500)), ), ), ]), )), ); } Future _logout(BuildContext context, WidgetRef ref) async { final theme = ShadTheme.of(context); final ok = await showDialog( context: context, builder: (ctx) => AlertDialog( shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(AppTheme.rXl)), title: Text('退出登录', style: TextStyle(color: theme.colorScheme.foreground)), content: Text('确定退出?', style: TextStyle(color: theme.colorScheme.mutedForeground)), actions: [ TextButton(onPressed: () => Navigator.pop(ctx, false), child: Text('取消', style: TextStyle(color: theme.colorScheme.mutedForeground))), TextButton(onPressed: () => Navigator.pop(ctx, true), child: Text('确定', style: TextStyle(color: theme.colorScheme.destructive))), ], ), ); if (ok == true) { await ref.read(authProvider.notifier).logout(); goRoute(ref, 'login'); } } }