219 lines
6.3 KiB
Dart
219 lines
6.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'tarjetaeta.dart';
|
|
import 'configuraciondomicilio.dart';
|
|
import 'notificaciones_service.dart';
|
|
|
|
class Domicilio {
|
|
final String id;
|
|
final String etiqueta;
|
|
final String direccion;
|
|
|
|
Domicilio({
|
|
required this.id,
|
|
required this.etiqueta,
|
|
required this.direccion,
|
|
});
|
|
}
|
|
|
|
class GestionDomiciliosScreen extends StatefulWidget {
|
|
const GestionDomiciliosScreen({super.key});
|
|
|
|
@override
|
|
State<GestionDomiciliosScreen> createState() =>
|
|
_GestionDomiciliosScreenState();
|
|
}
|
|
|
|
class _GestionDomiciliosScreenState
|
|
extends State<GestionDomiciliosScreen> {
|
|
|
|
final List<Domicilio> _misDomicilios = [
|
|
Domicilio(
|
|
id: '1',
|
|
etiqueta: 'Casa',
|
|
direccion: 'Av. Reforma 222, CDMX',
|
|
),
|
|
Domicilio(
|
|
id: '2',
|
|
etiqueta: 'Trabajo',
|
|
direccion: 'Benito Juárez 45',
|
|
),
|
|
];
|
|
|
|
bool _notificarInicioRuta = true;
|
|
bool _notificarAproximacion = true;
|
|
bool _notificarRetrasosFallas = false;
|
|
|
|
void _mostrarFormularioAgregar() {
|
|
showModalBottomSheet(
|
|
context: context,
|
|
isScrollControlled: true,
|
|
shape: const RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.vertical(
|
|
top: Radius.circular(24),
|
|
),
|
|
),
|
|
builder: (context) {
|
|
return PanelConfiguracionBottomSheet(
|
|
notificarInicioRuta: _notificarInicioRuta,
|
|
notificarAproximacion: _notificarAproximacion,
|
|
notificarRetrasosFallas: _notificarRetrasosFallas,
|
|
onDomicilioGuardado: (String etiqueta, String direccion) {
|
|
setState(() {
|
|
_misDomicilios.add(
|
|
Domicilio(
|
|
id: DateTime.now().toString(),
|
|
etiqueta: etiqueta,
|
|
direccion: direccion,
|
|
),
|
|
);
|
|
});
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
SnackBar(
|
|
content: Text('Domicilio "$etiqueta" agregado'),
|
|
backgroundColor: Colors.green,
|
|
),
|
|
);
|
|
},
|
|
onAlertasChanged: (bool valor, String tipo) {
|
|
setState(() {
|
|
switch (tipo) {
|
|
case 'inicio':
|
|
_notificarInicioRuta = valor;
|
|
break;
|
|
case 'aproximacion':
|
|
_notificarAproximacion = valor;
|
|
break;
|
|
case 'retrasos':
|
|
_notificarRetrasosFallas = valor;
|
|
break;
|
|
}
|
|
});
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
IconData _obtenerIcono(String etiqueta) {
|
|
switch (etiqueta.toLowerCase()) {
|
|
case 'casa':
|
|
return Icons.home;
|
|
case 'trabajo':
|
|
return Icons.business;
|
|
default:
|
|
return Icons.location_on;
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Scaffold(
|
|
backgroundColor: Colors.grey[100],
|
|
|
|
appBar: AppBar(
|
|
title: const Text('Mis Domicilios'),
|
|
backgroundColor: Colors.green,
|
|
foregroundColor: Colors.white,
|
|
|
|
actions: [
|
|
IconButton(
|
|
icon: const Icon(Icons.notifications_outlined),
|
|
tooltip: 'Alertas y Notificaciones',
|
|
onPressed: () async {
|
|
final resultado = await Navigator.push(
|
|
context,
|
|
MaterialPageRoute(
|
|
builder: (context) => AlertasNotificacionesScreen(
|
|
notificarInicioRuta: _notificarInicioRuta,
|
|
notificarAproximacion: _notificarAproximacion,
|
|
notificarRetrasosFallas: _notificarRetrasosFallas,
|
|
),
|
|
),
|
|
);
|
|
|
|
if (resultado != null) {
|
|
setState(() {
|
|
_notificarInicioRuta = resultado['inicio'];
|
|
_notificarAproximacion = resultado['aproximacion'];
|
|
_notificarRetrasosFallas = resultado['retrasos'];
|
|
});
|
|
}
|
|
},
|
|
),
|
|
],
|
|
),
|
|
|
|
body: Column(
|
|
children: [
|
|
|
|
// ← TARJETA ETA corregida
|
|
const Padding(
|
|
padding: EdgeInsets.all(16),
|
|
child: TarjetaEtaWidget(), // ← child bien cerrado aquí
|
|
),
|
|
|
|
const Padding(
|
|
padding: EdgeInsets.symmetric(horizontal: 16),
|
|
child: Align(
|
|
alignment: Alignment.centerLeft,
|
|
child: Text(
|
|
'Lugares Registrados',
|
|
style: TextStyle(
|
|
fontSize: 18,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
|
|
const SizedBox(height: 10),
|
|
|
|
Expanded(
|
|
child: ListView.builder(
|
|
itemCount: _misDomicilios.length,
|
|
itemBuilder: (context, index) {
|
|
final domicilio = _misDomicilios[index];
|
|
return Card(
|
|
margin: const EdgeInsets.symmetric(
|
|
horizontal: 16,
|
|
vertical: 8,
|
|
),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(15),
|
|
),
|
|
child: ListTile(
|
|
leading: CircleAvatar(
|
|
backgroundColor: Colors.green[100],
|
|
child: Icon(
|
|
_obtenerIcono(domicilio.etiqueta),
|
|
color: Colors.green,
|
|
),
|
|
),
|
|
title: Text(domicilio.etiqueta),
|
|
subtitle: Text(domicilio.direccion),
|
|
trailing: IconButton(
|
|
icon: const Icon(Icons.delete, color: Colors.red),
|
|
onPressed: () {
|
|
setState(() {
|
|
_misDomicilios.removeAt(index);
|
|
});
|
|
},
|
|
),
|
|
),
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
|
|
floatingActionButton: FloatingActionButton.extended(
|
|
onPressed: _mostrarFormularioAgregar,
|
|
backgroundColor: Colors.green,
|
|
foregroundColor: Colors.white,
|
|
icon: const Icon(Icons.add),
|
|
label: const Text('Agregar'),
|
|
),
|
|
);
|
|
}
|
|
} |