Files
hackathon-heavy-gears-7cc00…/lib/panel_configuracion_bottom_sheet.dart
2026-05-23 05:54:34 -06:00

183 lines
6.6 KiB
Dart

import 'package:flutter/material.dart';
class PanelConfiguracionBottomSheet extends StatefulWidget {
final Function(String etiqueta, String direccion) onDomicilioGuardado;
final bool notificarInicioRuta;
final bool notificarAproximacion;
final bool notificarRetrasosFallas;
final Function(bool nuevoValor, String tipoAlerta) onAlertasChanged;
const PanelConfiguracionBottomSheet({
super.key,
required this.onDomicilioGuardado,
required this.notificarInicioRuta,
required this.notificarAproximacion,
required this.notificarRetrasosFallas,
required this.onAlertasChanged,
});
@override
State<PanelConfiguracionBottomSheet> createState() => _PanelConfiguracionBottomSheetState();
}
class _PanelConfiguracionBottomSheetState extends State<PanelConfiguracionBottomSheet> {
final _formKey = GlobalKey<FormState>();
final _direccionController = TextEditingController();
String _etiquetaSeleccionada = 'Casa';
final List<String> _opcionesEtiquetas = ['Casa', 'Trabajo', 'Otro'];
late bool _inicioRuta;
late bool _aproximacion;
late bool _retrasosFallas;
@override
void initState() {
super.initState();
// Inicializamos los estados locales con los valores que vienen de la pantalla principal
_inicioRuta = widget.notificarInicioRuta;
_aproximacion = widget.notificarAproximacion;
_retrasosFallas = widget.notificarRetrasosFallas;
}
@override
void dispose() {
_direccionController.dispose();
super.dispose();
}
List<Widget> _construirOpcionesEtiquetas() {
return _opcionesEtiquetas.map((etiqueta) {
final bool isSelected = _etiquetaSeleccionada == etiqueta;
return Padding(
padding: const EdgeInsets.only(right: 8.0),
child: ChoiceChip(
label: Text(etiqueta),
selected: isSelected,
selectedColor: Colors.green[100],
checkmarkColor: Colors.green[800],
onSelected: (bool selected) {
setState(() {
_etiquetaSeleccionada = etiqueta;
});
},
),
);
}).toList();
}
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom + 24,
top: 24,
left: 24,
right: 24,
),
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Registrar Nuevo Domicilio',
style: Theme.of(context).textTheme.titleLarge?.copyWith(fontWeight: FontWeight.bold),
),
const SizedBox(height: 16),
Form(
key: _formKey,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'Etiqueta:',
style: TextStyle(fontWeight: FontWeight.bold, color: Colors.green[800]),
),
const SizedBox(height: 8),
Row(
children: _construirOpcionesEtiquetas(),
),
const SizedBox(height: 16),
TextFormField(
controller: _direccionController,
decoration: InputDecoration(
labelText: 'Dirección completa',
prefixIcon: const Icon(Icons.location_on, color: Colors.green),
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
),
validator: (value) {
if (value == null || value.trim().isEmpty) {
return 'Ingresa una dirección';
}
return null;
},
),
const SizedBox(height: 12),
SizedBox(
width: double.infinity,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.green[700],
foregroundColor: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
),
onPressed: () {
if (_formKey.currentState!.validate()) {
widget.onDomicilioGuardado(_etiquetaSeleccionada, _direccionController.text);
Navigator.pop(context); // Cierra el panel inferior automáticamente
}
},
child: const Text('Guardar Domicilio'),
),
),
],
),
),
const Padding(
padding: EdgeInsets.symmetric(vertical: 16.0),
child: Divider(color: Colors.black),
),
Row(
children: [
Icon(Icons.notifications_active_rounded, color: Colors.green[800]),
const SizedBox(width: 8),
Text(
'Alertas Operativas Push',
style: Theme.of(context).textTheme.titleMedium?.copyWith(fontWeight: FontWeight.bold),
),
],
),
const SizedBox(height: 8),
SwitchListTile(
title: const Text('Inicio de Ruta', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
value: _inicioRuta,
activeThumbColor: Colors.green[700],
onChanged: (bool value) {
setState(() => _inicioRuta = value);
widget.onAlertasChanged(value, 'inicio');
},
),
SwitchListTile(
title: const Text('Camión Próximo', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
value: _aproximacion,
activeThumbColor: Colors.green[700],
onChanged: (bool value) {
setState(() => _aproximacion = value);
widget.onAlertasChanged(value, 'aproximacion');
},
),
SwitchListTile(
title: const Text('Imprevistos y Retrasos', style: TextStyle(fontSize: 14, fontWeight: FontWeight.w600)),
value: _retrasosFallas,
activeThumbColor: Colors.green[700],
onChanged: (bool value) {
setState(() => _retrasosFallas = value);
widget.onAlertasChanged(value, 'retrasos');
},
),
],
),
),
);
}
}