import 'package:finalproject/theme/colors.dart'; import 'package:finalproject/theme/text_styles.dart'; import 'package:flutter/material.dart'; import 'package:finalproject/services/auth_service.dart'; import 'settings_controller.dart'; class SettingsScreen extends StatefulWidget { const SettingsScreen({super.key}); @override State createState() => _SettingsScreenState(); } class _SettingsScreenState extends State { late final SettingsController _controller; @override void initState() { super.initState(); _controller = SettingsController(); } void _showLogoutDialog() { showDialog( context: context, builder: (context) => AlertDialog( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(16), ), title: Text( 'Logout', style: AppTextStyles.headlineSmall.copyWith( color: AppColors.textPrimary, ), ), content: Text( 'Apakah Anda yakin ingin keluar dari aplikasi?', style: AppTextStyles.bodyMedium.copyWith( color: AppColors.textSecondary, ), ), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: Text( 'Batal', style: AppTextStyles.labelLarge.copyWith( color: AppColors.textSecondary, ), ), ), ElevatedButton( onPressed: () async { Navigator.pop(context); await AuthService.logout(); if (!context.mounted) return; Navigator.of( context, ).pushNamedAndRemoveUntil('/login', (route) => false); }, style: ElevatedButton.styleFrom( backgroundColor: AppColors.statusError, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(8), ), ), child: Text( 'Logout', style: AppTextStyles.labelLarge.copyWith(color: Colors.white), ), ), ], ), ); } @override Widget build(BuildContext context) { return AnimatedBuilder( animation: _controller, builder: (context, _) { return Scaffold( backgroundColor: AppColors.bgLight, appBar: AppBar( backgroundColor: AppColors.primaryBrown, elevation: 0, title: Text( 'Pengaturan', style: AppTextStyles.headlineLarge.copyWith(color: Colors.white), ), ), body: SingleChildScrollView( child: Padding( padding: const EdgeInsets.all(16.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Akun', style: AppTextStyles.headlineSmall.copyWith( color: AppColors.textPrimary, ), ), const SizedBox(height: 16), Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppColors.bgWhite, borderRadius: BorderRadius.circular(16), boxShadow: [AppColors.shadowLight], ), child: Row( children: [ Container( width: 60, height: 60, decoration: BoxDecoration( color: AppColors.primaryBrown, borderRadius: BorderRadius.circular(12), ), child: const Icon( Icons.person, color: Colors.white, size: 32, ), ), const SizedBox(width: 16), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Admin Sulastri', style: AppTextStyles.labelLarge.copyWith( color: AppColors.textPrimary, fontWeight: FontWeight.w700, ), ), const SizedBox(height: 4), Text( 'admin@sulastri.com', style: AppTextStyles.bodySmall.copyWith( color: AppColors.textSecondary, ), ), ], ), ), ], ), ), const SizedBox(height: 32), Text( 'Umum', style: AppTextStyles.headlineSmall.copyWith( color: AppColors.textPrimary, ), ), const SizedBox(height: 16), Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppColors.bgWhite, borderRadius: BorderRadius.circular(12), boxShadow: [AppColors.shadowLight], ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Icon( Icons.language, color: AppColors.primaryBrown, size: 24, ), const SizedBox(width: 12), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Bahasa', style: AppTextStyles.labelLarge.copyWith( color: AppColors.textPrimary, ), ), Text( 'Bahasa Indonesia', style: AppTextStyles.bodySmall.copyWith( color: AppColors.textSecondary, ), ), ], ), ], ), Icon( Icons.chevron_right, color: AppColors.textSecondary, ), ], ), ), const SizedBox(height: 12), Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppColors.bgWhite, borderRadius: BorderRadius.circular(12), boxShadow: [AppColors.shadowLight], ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Icon( Icons.notifications_outlined, color: AppColors.primaryBrown, size: 24, ), const SizedBox(width: 12), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Notifikasi', style: AppTextStyles.labelLarge.copyWith( color: AppColors.textPrimary, ), ), Text( 'Aktifkan notifikasi penting', style: AppTextStyles.bodySmall.copyWith( color: AppColors.textSecondary, ), ), ], ), ], ), Switch( value: _controller.notificationEnabled, onChanged: _controller.setNotificationEnabled, activeColor: AppColors.primaryBrown, ), ], ), ), const SizedBox(height: 32), Text( 'Keamanan', style: AppTextStyles.headlineSmall.copyWith( color: AppColors.textPrimary, ), ), const SizedBox(height: 16), Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppColors.bgWhite, borderRadius: BorderRadius.circular(12), boxShadow: [AppColors.shadowLight], ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Row( children: [ Icon( Icons.lock_outlined, color: AppColors.primaryBrown, size: 24, ), const SizedBox(width: 12), Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Ubah Password', style: AppTextStyles.labelLarge.copyWith( color: AppColors.textPrimary, ), ), Text( 'Perbarui password akun Anda', style: AppTextStyles.bodySmall.copyWith( color: AppColors.textSecondary, ), ), ], ), ], ), Icon( Icons.chevron_right, color: AppColors.textSecondary, ), ], ), ), const SizedBox(height: 32), SizedBox( width: double.infinity, child: ElevatedButton.icon( onPressed: _showLogoutDialog, icon: const Icon(Icons.logout), label: const Text('Logout'), style: ElevatedButton.styleFrom( backgroundColor: AppColors.statusError, foregroundColor: Colors.white, padding: const EdgeInsets.symmetric(vertical: 14), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), ), ), ), const SizedBox(height: 32), Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppColors.bgLight, borderRadius: BorderRadius.circular(12), border: Border.all(color: AppColors.grey300), ), child: Column( children: [ Text( 'Prediksi Stok Bahan Kue', style: AppTextStyles.labelLarge.copyWith( color: AppColors.textPrimary, fontWeight: FontWeight.w700, ), ), const SizedBox(height: 8), Text( 'Version 1.0.0', style: AppTextStyles.bodySmall.copyWith( color: AppColors.textSecondary, ), ), const SizedBox(height: 12), Text( '© 2025 Tobaku Sulastri', style: AppTextStyles.bodySmall.copyWith( color: AppColors.textTertiary, ), textAlign: TextAlign.center, ), ], ), ), ], ), ), ), bottomNavigationBar: BottomNavigationBar( currentIndex: _controller.selectedIndex, onTap: (index) { _controller.setSelectedIndex(index); switch (index) { case 0: Navigator.of(context).pushNamed('/dashboard'); break; case 1: Navigator.of(context).pushNamed('/products'); break; case 2: Navigator.of(context).pushNamed('/transaction'); break; case 3: Navigator.of(context).pushNamed('/prediction'); break; case 4: Navigator.of(context).pushNamed('/reports'); break; case 5: break; } }, type: BottomNavigationBarType.fixed, backgroundColor: Colors.white, items: const [ BottomNavigationBarItem( icon: Icon(Icons.home_outlined), label: 'Dashboard', ), BottomNavigationBarItem( icon: Icon(Icons.shopping_bag_outlined), label: 'Produk', ), BottomNavigationBarItem( icon: Icon(Icons.shopping_cart_outlined), label: 'Stok Masuk', ), BottomNavigationBarItem( icon: Icon(Icons.trending_up_outlined), label: 'Prediksi', ), BottomNavigationBarItem( icon: Icon(Icons.description_outlined), label: 'Laporan', ), BottomNavigationBarItem( icon: Icon(Icons.settings_outlined), label: 'Pengaturan', ), ], ), ); }, ); } @override void dispose() { _controller.dispose(); super.dispose(); } }