import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../core/auth/auth_notifier.dart'; import '../../core/auth/auth_state.dart'; import '../../core/theme/app_theme.dart'; class ProfileScreen extends ConsumerWidget { const ProfileScreen({super.key}); @override Widget build(BuildContext context, WidgetRef ref) { final authState = ref.watch(authProvider); final user = authState is AuthAuthenticated ? authState.user : null; return Scaffold( appBar: AppBar(title: const Text('Profil')), body: ListView( padding: const EdgeInsets.all(16), children: [ // Avatar Center( child: Column( children: [ CircleAvatar( radius: 40, backgroundColor: AppColors.primaryLight, child: Text( user?.username.isNotEmpty == true ? user!.username[0].toUpperCase() : '?', style: const TextStyle(fontSize: 32, fontWeight: FontWeight.w700, color: AppColors.primary), ), ), const SizedBox(height: 12), Text(user?.username ?? '', style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w700)), const SizedBox(height: 4), Container( padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), decoration: BoxDecoration( color: AppColors.primaryLight, borderRadius: BorderRadius.circular(999), ), child: Text(user?.role ?? '', style: const TextStyle(fontSize: 12, fontWeight: FontWeight.w600, color: AppColors.primaryDark)), ), ], ), ), const SizedBox(height: 32), // Menu _MenuItem( icon: Icons.lock_outline, label: 'Ganti Password', onTap: () => context.push('/profile/password'), ), const Divider(height: 1), _MenuItem( icon: Icons.logout, label: 'Keluar', color: AppColors.danger, onTap: () async { final confirm = await showDialog(context: context, builder: (_) => AlertDialog( title: const Text('Keluar'), content: const Text('Apakah Anda yakin ingin keluar?'), actions: [ TextButton(onPressed: () => Navigator.pop(context, false), child: const Text('Batal')), TextButton(onPressed: () => Navigator.pop(context, true), child: const Text('Keluar', style: TextStyle(color: AppColors.danger))), ], )); if (confirm == true) { await ref.read(authProvider.notifier).logout(); } }, ), ], ), ); } } class _MenuItem extends StatelessWidget { final IconData icon; final String label; final VoidCallback onTap; final Color? color; const _MenuItem({required this.icon, required this.label, required this.onTap, this.color}); @override Widget build(BuildContext context) => ListTile( leading: Icon(icon, color: color ?? AppColors.text, size: 22), title: Text(label, style: TextStyle(color: color ?? AppColors.text, fontSize: 14, fontWeight: FontWeight.w500)), trailing: const Icon(Icons.chevron_right, color: AppColors.textSub), onTap: onTap, ); }