import 'package:flutter/material.dart'; import '../constants/app_colors.dart'; import '../services/supabase_service.dart'; class SettingsScreen extends StatefulWidget { const SettingsScreen({super.key}); @override State createState() => _SettingsScreenState(); } class _SettingsScreenState extends State { bool _isNightMode = true; bool _notificationsEnabled = true; String _selectedLanguage = 'Português'; @override Widget build(BuildContext context) { final user = SupabaseService.currentUser; final userName = user?.userMetadata?['name'] ?? user?.email?.split('@')[0] ?? 'Usuário'; final userEmail = user?.email ?? 'usuario@exemplo.com'; return Scaffold( backgroundColor: AppColors.background, appBar: AppBar( title: const Text( 'CONFIGURAÇÕES', style: TextStyle( color: Colors.white, fontSize: 20, fontWeight: FontWeight.bold, ), ), backgroundColor: AppColors.background, elevation: 0, iconTheme: const IconThemeData(color: Colors.white), leading: IconButton( icon: const Icon(Icons.arrow_back, color: Colors.white), onPressed: () => Navigator.pop(context), ), ), body: SingleChildScrollView( padding: const EdgeInsets.all(16), child: Column( children: [ // User Profile Section Container( padding: const EdgeInsets.all(20), decoration: BoxDecoration( color: AppColors.backgroundGrey, borderRadius: BorderRadius.circular(16), ), child: Row( children: [ Container( width: 60, height: 60, decoration: BoxDecoration( color: AppColors.buttonColor, borderRadius: BorderRadius.circular(30), ), child: const Icon( Icons.person, color: Colors.white, size: 30, ), ), const SizedBox(width: 16), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( userName, style: const TextStyle( color: Colors.white, fontSize: 18, fontWeight: FontWeight.bold, ), ), Text( userEmail, style: TextStyle( color: Colors.white.withOpacity(0.7), fontSize: 14, ), ), ], ), ), IconButton( icon: const Icon(Icons.edit, color: AppColors.buttonColor), onPressed: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Editar perfil'), backgroundColor: AppColors.buttonColor, ), ); }, ), ], ), ), const SizedBox(height: 24), // Settings Items Container( decoration: BoxDecoration( color: AppColors.backgroundGrey, borderRadius: BorderRadius.circular(16), ), child: Column( children: [ _buildSettingsItem( icon: Icons.schedule, title: 'Ajustar Data e Hora', onTap: () { _showDatePicker(context); }, ), _buildDivider(), _buildSettingsItem( icon: Icons.dark_mode, title: 'Modo Noturno', trailing: Switch( value: _isNightMode, onChanged: (value) { setState(() { _isNightMode = value; }); }, activeColor: AppColors.buttonColor, ), ), _buildDivider(), _buildSettingsItem( icon: Icons.language, title: 'Idioma', trailing: Text( _selectedLanguage, style: TextStyle( color: Colors.white.withOpacity(0.7), fontSize: 16, ), ), onTap: () { _showLanguageSelector(context); }, ), _buildDivider(), _buildSettingsItem( icon: Icons.accessibility, title: 'Acessibilidade', onTap: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Acessibilidade'), backgroundColor: AppColors.buttonColor, ), ); }, ), _buildDivider(), _buildSettingsItem( icon: Icons.notifications, title: 'Notificações', trailing: Switch( value: _notificationsEnabled, onChanged: (value) { setState(() { _notificationsEnabled = value; }); }, activeColor: AppColors.buttonColor, ), ), _buildDivider(), _buildSettingsItem( icon: Icons.privacy_tip, title: 'Privacidade e Segurança', onTap: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Privacidade e Segurança'), backgroundColor: AppColors.buttonColor, ), ); }, ), _buildDivider(), _buildSettingsItem( icon: Icons.description, title: 'Termos de Uso', onTap: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar( content: Text('Termos de Uso'), backgroundColor: AppColors.buttonColor, ), ); }, ), _buildDivider(), _buildSettingsItem( icon: Icons.info, title: 'Sobre', onTap: () { _showAboutDialog(context); }, ), ], ), ), const SizedBox(height: 24), // Logout Button Container( width: double.infinity, child: ElevatedButton( onPressed: () { _showLogoutDialog(context); }, style: ElevatedButton.styleFrom( backgroundColor: Colors.red, padding: const EdgeInsets.symmetric(vertical: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(12), ), ), child: const Text( 'Sair', style: TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.bold, ), ), ), ), ], ), ), ); } Widget _buildSettingsItem({ required IconData icon, required String title, Widget? trailing, VoidCallback? onTap, }) { return ListTile( leading: Icon(icon, color: AppColors.buttonColor, size: 24), title: Text( title, style: const TextStyle( color: Colors.white, fontSize: 16, fontWeight: FontWeight.w500, ), ), trailing: trailing, onTap: onTap, ); } Widget _buildDivider() { return Divider( color: Colors.white.withOpacity(0.1), height: 1, indent: 16, endIndent: 16, ); } void _showDatePicker(BuildContext context) { showDatePicker( context: context, initialDate: DateTime.now(), firstDate: DateTime(2020), lastDate: DateTime(2025), ).then((date) { if (date != null) { ScaffoldMessenger.of(context).showSnackBar( SnackBar( content: Text('Data selecionada: ${date.toString().split(' ')[0]}'), backgroundColor: AppColors.buttonColor, ), ); } }); } void _showLanguageSelector(BuildContext context) { showDialog( context: context, builder: (context) => AlertDialog( backgroundColor: AppColors.backgroundGrey, title: const Text( 'Selecionar Idioma', style: TextStyle(color: Colors.white), ), content: Column( mainAxisSize: MainAxisSize.min, children: [ _buildLanguageOption('Português'), _buildLanguageOption('English'), _buildLanguageOption('Español'), ], ), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text( 'Cancelar', style: TextStyle(color: AppColors.buttonColor), ), ), ], ), ); } Widget _buildLanguageOption(String language) { return RadioListTile( title: Text(language, style: const TextStyle(color: Colors.white)), value: language, groupValue: _selectedLanguage, onChanged: (value) { setState(() { _selectedLanguage = value!; }); Navigator.pop(context); }, activeColor: AppColors.buttonColor, ); } void _showAboutDialog(BuildContext context) { showDialog( context: context, builder: (context) => AlertDialog( backgroundColor: AppColors.backgroundGrey, title: const Text('Sobre', style: TextStyle(color: Colors.white)), content: const Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'Run Vision Pro', style: TextStyle( color: Colors.white, fontWeight: FontWeight.bold, ), ), SizedBox(height: 8), Text('Versão: 1.0.0', style: TextStyle(color: Colors.white70)), SizedBox(height: 8), Text( 'Aplicativo de corrida com estatísticas e mapas', style: TextStyle(color: Colors.white70), ), ], ), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text( 'OK', style: TextStyle(color: AppColors.buttonColor), ), ), ], ), ); } void _showLogoutDialog(BuildContext context) { showDialog( context: context, builder: (context) => AlertDialog( backgroundColor: AppColors.backgroundGrey, title: const Text( 'Confirmar Logout', style: TextStyle(color: Colors.white), ), content: const Text( 'Tem certeza que deseja sair?', style: TextStyle(color: Colors.white70), ), actions: [ TextButton( onPressed: () => Navigator.pop(context), child: const Text( 'Cancelar', style: TextStyle(color: AppColors.buttonColor), ), ), TextButton( onPressed: () { Navigator.pop(context); Navigator.pushReplacementNamed(context, '/'); }, child: const Text('Sair', style: TextStyle(color: Colors.red)), ), ], ), ); } }