import 'package:flutter/material.dart'; import '../widgets/app_menu_button.dart'; class SettingsPage extends StatefulWidget { const SettingsPage({Key? key}) : super(key: key); @override State createState() => _SettingsPageState(); } class _SettingsPageState extends State { final _formKey = GlobalKey(); // Notificaciones bool _soundEnabled = true; bool _vibrationEnabled = true; bool _notificationsEnabled = true; double _volume = 0.8; // Alarma int _snoozeMinutes = 5; int _repeatTimes = 3; String _selectedTone = 'Predeterminado'; final List _tones = [ 'Predeterminado', 'Clásico', 'Digital', 'Suave', 'Urgente', ]; // Cuenta final _nameController = TextEditingController(text: 'Usuario'); final _emailController = TextEditingController(text: 'usuario@email.com'); @override void dispose() { _nameController.dispose(); _emailController.dispose(); super.dispose(); } void _saveSettings() { if (_formKey.currentState!.validate()) { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Configuración guardada')), ); } } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Configuración'), actions: [ TextButton( onPressed: _saveSettings, child: const Text('Guardar', style: TextStyle(color: Colors.white)), ), const AppMenuButton(), ], ), body: Form( key: _formKey, child: ListView( children: [ _buildSectionHeader('Cuenta'), Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: TextFormField( controller: _nameController, decoration: const InputDecoration( labelText: 'Nombre', prefixIcon: Icon(Icons.person), border: OutlineInputBorder(), ), validator: (value) { if (value == null || value.isEmpty) { return 'El nombre no puede estar vacío'; } return null; }, ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: TextFormField( controller: _emailController, keyboardType: TextInputType.emailAddress, decoration: const InputDecoration( labelText: 'Email', prefixIcon: Icon(Icons.email), border: OutlineInputBorder(), ), validator: (value) { if (value == null || !value.contains('@')) { return 'Email no válido'; } return null; }, ), ), _buildSectionHeader('Notificaciones'), SwitchListTile( title: const Text('Notificaciones'), subtitle: const Text('Activar alertas del sistema'), secondary: const Icon(Icons.notifications), value: _notificationsEnabled, onChanged: (val) => setState(() => _notificationsEnabled = val), ), SwitchListTile( title: const Text('Sonido'), subtitle: const Text('Reproducir sonido al activar alarma'), secondary: const Icon(Icons.volume_up), value: _soundEnabled, onChanged: (val) => setState(() => _soundEnabled = val), ), if (_soundEnabled) Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: Row( children: [ const Icon(Icons.volume_down, color: Colors.grey), Expanded( child: Slider( value: _volume, onChanged: (val) => setState(() => _volume = val), ), ), const Icon(Icons.volume_up, color: Colors.grey), ], ), ), SwitchListTile( title: const Text('Vibración'), subtitle: const Text('Vibrar al activar alarma'), secondary: const Icon(Icons.vibration), value: _vibrationEnabled, onChanged: (val) => setState(() => _vibrationEnabled = val), ), _buildSectionHeader('Alarma'), Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: DropdownButtonFormField( value: _selectedTone, decoration: const InputDecoration( labelText: 'Tono de alarma', prefixIcon: Icon(Icons.music_note), border: OutlineInputBorder(), ), items: _tones .map((t) => DropdownMenuItem(value: t, child: Text(t))) .toList(), onChanged: (val) => setState(() => _selectedTone = val!), ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: Row( children: [ const Icon(Icons.snooze, color: Colors.grey), const SizedBox(width: 12), const Text('Posponer (minutos):'), const Spacer(), DropdownButton( value: _snoozeMinutes, items: [1, 5, 10, 15, 30] .map((m) => DropdownMenuItem(value: m, child: Text('$m min'))) .toList(), onChanged: (val) => setState(() => _snoozeMinutes = val!), ), ], ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8), child: Row( children: [ const Icon(Icons.repeat, color: Colors.grey), const SizedBox(width: 12), const Text('Repeticiones:'), const Spacer(), DropdownButton( value: _repeatTimes, items: [1, 2, 3, 5, 10] .map((n) => DropdownMenuItem(value: n, child: Text('$n veces'))) .toList(), onChanged: (val) => setState(() => _repeatTimes = val!), ), ], ), ), const SizedBox(height: 16), Padding( padding: const EdgeInsets.symmetric(horizontal: 16), child: OutlinedButton.icon( onPressed: () { ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Sesión cerrada')), ); Navigator.of(context).popUntil((route) => route.isFirst); }, icon: const Icon(Icons.logout, color: Colors.red), label: const Text('Cerrar sesión', style: TextStyle(color: Colors.red)), style: OutlinedButton.styleFrom( side: const BorderSide(color: Colors.red), minimumSize: const Size(double.infinity, 50), ), ), ), const SizedBox(height: 24), ], ), ), ); } Widget _buildSectionHeader(String title) { return Padding( padding: const EdgeInsets.fromLTRB(16, 20, 16, 4), child: Text( title.toUpperCase(), style: TextStyle( fontSize: 12, fontWeight: FontWeight.bold, color: Colors.blue.shade700, letterSpacing: 1.2, ), ), ); } }