271 lines
9.0 KiB
Dart
271 lines
9.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'notificaciones_service.dart';
|
|
|
|
// ← Lista de colonias disponibles (igual que en ruta_exclusiva.dart)
|
|
const List<String> _coloniasDisponibles = [
|
|
'Zona Centro',
|
|
'Las Arboledas',
|
|
'Trojes',
|
|
'San Juanico',
|
|
'Los Olivos',
|
|
'Rancho Seco',
|
|
'Las Insurgentes',
|
|
];
|
|
|
|
class PanelConfiguracionBottomSheet extends StatefulWidget {
|
|
// ← colonia agregada al callback
|
|
final Function(String etiqueta, String direccion, String colonia) onDomicilioGuardado;
|
|
final bool notificarInicioRuta;
|
|
final bool notificarAproximacion;
|
|
final bool notificarRetrasosFallas;
|
|
final Function(bool, String) 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';
|
|
String _coloniaSeleccionada = _coloniasDisponibles[0]; // ← NUEVO
|
|
|
|
final List<String> _opcionesEtiquetas = ['Casa', 'Trabajo', 'Otro'];
|
|
|
|
late bool _inicioRuta;
|
|
late bool _aproximacion;
|
|
late bool _retrasosFallas;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_inicioRuta = widget.notificarInicioRuta;
|
|
_aproximacion = widget.notificarAproximacion;
|
|
_retrasosFallas = widget.notificarRetrasosFallas;
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_direccionController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
@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: [
|
|
|
|
// ── Etiqueta ──
|
|
Text(
|
|
'Etiqueta:',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.green[800],
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Row(children: _opcionesEtpciones()),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
// ── Dirección ──
|
|
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: 16),
|
|
|
|
// ── Selector de colonia ── NUEVO
|
|
Text(
|
|
'Colonia:',
|
|
style: TextStyle(
|
|
fontWeight: FontWeight.bold,
|
|
color: Colors.green[800],
|
|
),
|
|
),
|
|
const SizedBox(height: 8),
|
|
Container(
|
|
width: double.infinity,
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
decoration: BoxDecoration(
|
|
border: Border.all(color: Colors.grey),
|
|
borderRadius: BorderRadius.circular(12),
|
|
),
|
|
child: DropdownButtonHideUnderline(
|
|
child: DropdownButton<String>(
|
|
value: _coloniaSeleccionada,
|
|
isExpanded: true,
|
|
icon: const Icon(Icons.arrow_drop_down, color: Colors.green),
|
|
items: _coloniasDisponibles.map((colonia) {
|
|
return DropdownMenuItem(
|
|
value: colonia,
|
|
child: Text(colonia),
|
|
);
|
|
}).toList(),
|
|
onChanged: (value) {
|
|
setState(() {
|
|
_coloniaSeleccionada = value!;
|
|
});
|
|
},
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
// ── Botón guardar ──
|
|
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()) {
|
|
// ← pasa también la colonia
|
|
widget.onDomicilioGuardado(
|
|
_etiquetaSeleccionada,
|
|
_direccionController.text,
|
|
_coloniaSeleccionada,
|
|
);
|
|
Navigator.pop(context);
|
|
}
|
|
},
|
|
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');
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
List<Widget> _opcionesEtpciones() {
|
|
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();
|
|
}
|
|
} |