import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:gap/gap.dart'; import '../../../../core/utils/extensions.dart'; import '../../../../shared/providers/auth_provider.dart'; class UserHomeScreen extends ConsumerWidget { const UserHomeScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final authState = ref.watch(authStateProvider); return SingleChildScrollView( padding: const EdgeInsets.all(24), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ // 환영 메시지 authState.when( data: (user) => Text( '안녕하세요, ${user?.name ?? '사용자'}님!', style: context.textTheme.headlineMedium?.copyWith( fontWeight: FontWeight.bold, ), ), loading: () => const SizedBox.shrink(), error: (_, __) => const SizedBox.shrink(), ), const Gap(8), Text( '오늘의 요약을 확인하세요', style: context.textTheme.bodyLarge?.copyWith( color: context.colorScheme.onSurfaceVariant, ), ), const Gap(24), // 요약 카드 그리드 LayoutBuilder( builder: (context, constraints) { final crossAxisCount = context.isDesktop ? 4 : context.isTablet ? 2 : 1; return GridView.count( crossAxisCount: crossAxisCount, shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), mainAxisSpacing: 16, crossAxisSpacing: 16, childAspectRatio: 1.8, children: const [ _SummaryCard( title: '진행중 작업', value: '12', icon: Icons.pending_actions, color: Colors.blue, ), _SummaryCard( title: '완료된 작업', value: '48', icon: Icons.check_circle_outline, color: Colors.green, ), _SummaryCard( title: '알림', value: '3', icon: Icons.notifications_outlined, color: Colors.orange, ), _SummaryCard( title: '메시지', value: '7', icon: Icons.mail_outlined, color: Colors.purple, ), ], ); }, ), const Gap(24), // 최근 활동 Text( '최근 활동', style: context.textTheme.titleLarge?.copyWith( fontWeight: FontWeight.bold, ), ), const Gap(16), Card( child: ListView.separated( shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), itemCount: 5, separatorBuilder: (_, __) => const Divider(height: 1), itemBuilder: (context, index) => ListTile( leading: CircleAvatar( backgroundColor: context.colorScheme.primaryContainer, child: Icon( Icons.task_alt, color: context.colorScheme.primary, ), ), title: Text('활동 항목 ${index + 1}'), subtitle: Text('${index + 1}시간 전'), trailing: const Icon(Icons.chevron_right), ), ), ), ], ), ); } } class _SummaryCard extends StatelessWidget { const _SummaryCard({ required this.title, required this.value, required this.icon, required this.color, }); final String title; final String value; final IconData icon; final Color color; @override Widget build(BuildContext context) { return Card( child: Padding( padding: const EdgeInsets.all(20), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( title, style: Theme.of(context).textTheme.bodyMedium?.copyWith( color: Theme.of(context).colorScheme.onSurfaceVariant, ), ), Icon(icon, color: color, size: 24), ], ), Text( value, style: Theme.of(context).textTheme.headlineMedium?.copyWith( fontWeight: FontWeight.bold, ), ), ], ), ), ); } }