Mi primer commit
This commit is contained in:
66
lib/alertas_provider.dart
Normal file
66
lib/alertas_provider.dart
Normal file
@@ -0,0 +1,66 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'notificaciones_service.dart';
|
||||
|
||||
class AlertasOperativasProvider with ChangeNotifier {
|
||||
final NotificacionesService _notificacionesService = NotificacionesService();
|
||||
|
||||
// Estados de los interruptores configurables por el usuario
|
||||
bool _notificarInicioRuta = true;
|
||||
bool _notificarAproximacion = true;
|
||||
bool _notificarRetrasosFallas = true;
|
||||
|
||||
// Getters para leer el estado desde las pantallas
|
||||
bool get notificarInicioRuta => _notificarInicioRuta;
|
||||
bool get notificarAproximacion => _notificarAproximacion;
|
||||
bool get notificarRetrasosFallas => _notificarRetrasosFallas;
|
||||
|
||||
// Funciones para cambiar los interruptores (Switches)
|
||||
void cambiarNotificarInicioRuta(bool valor) {
|
||||
_notificarInicioRuta = valor;
|
||||
notifyListeners(); // Notifica a la interfaz que se redibuje
|
||||
}
|
||||
|
||||
void cambiarNotificarAproximacion(bool valor) {
|
||||
_notificarAproximacion = valor;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void cambiarNotificarRetrasosFallas(bool valor) {
|
||||
_notificarRetrasosFallas = valor;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
// =========================================================
|
||||
// SIMULACIÓN DE DISPAROS DE ALERTAS PUSH REALES
|
||||
// =========================================================
|
||||
|
||||
void simularAlertaInicioRuta() {
|
||||
if (_notificarInicioRuta) {
|
||||
_notificacionesService.mostrarNotificacionPush(
|
||||
id: 1,
|
||||
titulo: 'Ruta Iniciada 🟢',
|
||||
mensaje: 'El camión recolector ha comenzado su recorrido hacia tu sector.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void simularAlertaAproximacion() {
|
||||
if (_notificarAproximacion) {
|
||||
_notificacionesService.mostrarNotificacionPush(
|
||||
id: 2,
|
||||
titulo: 'Camión Cercano ⏰',
|
||||
mensaje: 'El recolector llegará a tu domicilio en aproximadamente 15 minutos.',
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
void simularAlertaRetrasoOConversion() {
|
||||
if (_notificarRetrasosFallas) {
|
||||
_notificacionesService.mostrarNotificacionPush(
|
||||
id: 3,
|
||||
titulo: 'Retraso en la Ruta ⚠️',
|
||||
mensaje: 'Aviso: Retraso operativo por tráfico pesado o fallas mecánicas en la zona.',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
177
lib/configuraciondomicilio.dart
Normal file
177
lib/configuraciondomicilio.dart
Normal file
@@ -0,0 +1,177 @@
|
||||
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, 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';
|
||||
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: [
|
||||
Text('Etiqueta:', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.green[800])),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: _opcionesEtpciones(),
|
||||
),
|
||||
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);
|
||||
}
|
||||
},
|
||||
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,
|
||||
activeColor: 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,
|
||||
activeColor: 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,
|
||||
activeColor: 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();
|
||||
}
|
||||
}
|
||||
269
lib/domicilios.dart
Normal file
269
lib/domicilios.dart
Normal file
@@ -0,0 +1,269 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'tarjetaeta.dart';
|
||||
import 'configuraciondomicilio.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. Paseo de la Reforma 222, CDMX'),
|
||||
Domicilio(id: '2', etiqueta: 'Trabajo', direccion: 'Colonia Centro, Calle Benito Juárez 45'),
|
||||
];
|
||||
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
final _direccionController = TextEditingController();
|
||||
String _etiquetaSeleccionada = 'Casa';
|
||||
|
||||
final List<String> _opcionesEtiquetas = ['Casa', 'Trabajo', 'Otro'];
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_direccionController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _mostrarFormularioAgregar(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
builder: (context) {
|
||||
return StatefulBuilder(
|
||||
builder: (BuildContext context, StateSetter setModalState) {
|
||||
return Padding(
|
||||
padding: EdgeInsets.only(
|
||||
bottom: MediaQuery.of(context).viewInsets.bottom + 24,
|
||||
top: 24,
|
||||
left: 24,
|
||||
right: 24,
|
||||
),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
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: 8),
|
||||
Text(
|
||||
'Asigna una etiqueta para identificar dónde recogeremos los residuos.',
|
||||
style: TextStyle(color: Colors.grey[600]),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
Text('Etiqueta:', style: TextStyle(fontWeight: FontWeight.bold, color: Colors.green[800])),
|
||||
const SizedBox(height: 8),
|
||||
Row(
|
||||
children: _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],
|
||||
labelStyle: TextStyle(
|
||||
color: isSelected ? Colors.green[800] : Colors.black,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
onSelected: (bool selected) {
|
||||
setModalState(() {
|
||||
_etiquetaSeleccionada = etiqueta;
|
||||
});
|
||||
},
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
TextFormField(
|
||||
controller: _direccionController,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Dirección completa',
|
||||
hintText: 'Calle, número, colonia...',
|
||||
prefixIcon: const Icon(Icons.location_on, color: Colors.green),
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: const BorderSide(color: Colors.green, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return 'Por favor, ingresa una dirección';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 50,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green[700],
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
setState(() {
|
||||
_misDomicilios.add(
|
||||
Domicilio(
|
||||
id: DateTime.now().toString(),
|
||||
etiqueta: _etiquetaSeleccionada,
|
||||
direccion: _direccionController.text,
|
||||
),
|
||||
);
|
||||
});
|
||||
_direccionController.clear();
|
||||
Navigator.pop(context);
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('¡Domicilio registrado con éxito!'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
child: const Text('Guardar Domicilio', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
IconData _obtenerIcono(String etiqueta) {
|
||||
switch (etiqueta.toLowerCase()) {
|
||||
case 'casa':
|
||||
return Icons.home_rounded;
|
||||
case 'trabajo':
|
||||
return Icons.business_center_rounded;
|
||||
default:
|
||||
return Icons.place_rounded;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Mis Domicilios', style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
backgroundColor: Colors.green[700],
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
// USAMOS EL WIDGET EXTERNO AQUÍ DIRECTAMENTE
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(top: 16.0, left: 16.0, right: 16.0),
|
||||
child: TarjetaEtaWidget(
|
||||
horaInicio: '7:20 p.m.',
|
||||
horaFin: '7:35 p.m.',
|
||||
minutosRestantes: 15,
|
||||
estadoCamion: 'en_camino',
|
||||
),
|
||||
),
|
||||
|
||||
const Padding(
|
||||
padding: EdgeInsets.only(left: 18.0, top: 16.0, bottom: 4.0),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
'Lugares de Recolección',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold, color: Colors.grey),
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
Expanded(
|
||||
child: _misDomicilios.isEmpty
|
||||
? Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.no_accounts_rounded, size: 80, color: Colors.grey[400]),
|
||||
const SizedBox(height: 16),
|
||||
Text('Aún no tienes domicilios registrados', style: TextStyle(color: Colors.grey[600], fontSize: 16)),
|
||||
],
|
||||
),
|
||||
)
|
||||
: ListView.builder(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
||||
itemCount: _misDomicilios.length,
|
||||
itemBuilder: (context, index) {
|
||||
final domicilio = _misDomicilios[index];
|
||||
|
||||
return Card(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
child: ListTile(
|
||||
leading: CircleAvatar(
|
||||
backgroundColor: Colors.green[50],
|
||||
child: Icon(_obtenerIcono(domicilio.etiqueta), color: Colors.green[700]),
|
||||
),
|
||||
title: Text(
|
||||
domicilio.etiqueta,
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
subtitle: Text(domicilio.direccion, maxLines: 2, overflow: TextOverflow.ellipsis),
|
||||
trailing: IconButton(
|
||||
icon: const Icon(Icons.delete_outline, color: Colors.redAccent),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_misDomicilios.removeAt(index);
|
||||
});
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => _mostrarFormularioAgregar(context),
|
||||
backgroundColor: Colors.green[700],
|
||||
foregroundColor: Colors.white,
|
||||
icon: const Icon(Icons.add_location_alt_rounded),
|
||||
label: const Text('Agregar lugar'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
181
lib/gestion_domicilios.dart
Normal file
181
lib/gestion_domicilios.dart
Normal file
@@ -0,0 +1,181 @@
|
||||
import 'package:flutter/material.dart';
|
||||
// Asegúrate de que el nombre del import coincida exactamente con tu archivo creado
|
||||
import 'panel_configuracion_bottom_sheet.dart';
|
||||
|
||||
// ==========================================
|
||||
// 1. MODELO DE DATOS
|
||||
// ==========================================
|
||||
class Domicilio {
|
||||
final String id;
|
||||
final String etiqueta;
|
||||
final String direccion;
|
||||
|
||||
Domicilio({required this.id, required this.etiqueta, required this.direccion});
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 2. COMPONENTE: TARJETA DE LLEGADA (ETA)
|
||||
// ==========================================
|
||||
class TarjetaEtaWidget extends StatelessWidget {
|
||||
final String horaInicio;
|
||||
final String horaFin;
|
||||
final int minutosRestantes;
|
||||
final String estadoCamion;
|
||||
|
||||
const TarjetaEtaWidget({
|
||||
super.key,
|
||||
required this.horaInicio,
|
||||
required this.horaFin,
|
||||
required this.minutosRestantes,
|
||||
required this.estadoCamion,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color colorTema = estadoCamion == 'retrasado' ? Colors.amber[700]! : Colors.green[700]!;
|
||||
|
||||
return Card(
|
||||
elevation: 3,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.local_shipping_rounded, color: colorTema),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
estadoCamion == 'retrasado' ? 'Estado: Demorado' : 'Ruta en Progreso',
|
||||
style: TextStyle(color: colorTema, fontWeight: FontWeight.bold),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Llega en aproximadamente $minutosRestantes minutos',
|
||||
style: const TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
|
||||
),
|
||||
Text('Entre las $horaInicio y las $horaFin.'),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ==========================================
|
||||
// 3. PANTALLA PRINCIPAL
|
||||
// ==========================================
|
||||
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. Paseo de la Reforma 222, CDMX'),
|
||||
Domicilio(id: '2', etiqueta: 'Trabajo', direccion: 'Colonia Centro, Calle Benito Juárez 45'),
|
||||
];
|
||||
|
||||
bool _notificarInicioRuta = true;
|
||||
bool _notificarAproximacion = true;
|
||||
bool _notificarRetrasosFallas = true;
|
||||
|
||||
void _simularNotificacionPush({required String titulo, required String mensaje, required IconData icono, required Color color}) {
|
||||
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
behavior: SnackBarBehavior.floating,
|
||||
backgroundColor: Colors.grey[900],
|
||||
content: Row(
|
||||
children: [
|
||||
Icon(icono, color: color),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(child: Text(titulo)),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _abrirAjustesYFormulario(BuildContext context) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
shape: const RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.vertical(top: Radius.circular(24)),
|
||||
),
|
||||
builder: (context) {
|
||||
// Aquí llamamos a la clase externa. Al limpiar el archivo,
|
||||
// Android Studio sabrá perfectamente que nos referimos al Widget.
|
||||
return PanelConfiguracionBottomSheet(
|
||||
notificarInicioRuta: _notificarInicioRuta,
|
||||
notificarAproximacion: _notificarAproximacion,
|
||||
notificarRetrasosFallas: _notificarRetrasosFallas,
|
||||
onDomicilioGuardado: (etiqueta, direccion) {
|
||||
setState(() {
|
||||
_misDomicilios.add(Domicilio(
|
||||
id: DateTime.now().toString(),
|
||||
etiqueta: etiqueta,
|
||||
direccion: direccion,
|
||||
));
|
||||
});
|
||||
},
|
||||
onAlertasChanged: (nuevoValor, tipoAlerta) {
|
||||
setState(() {
|
||||
if (tipoAlerta == 'inicio') _notificarInicioRuta = nuevoValor;
|
||||
if (tipoAlerta == 'aproximacion') _notificarAproximacion = nuevoValor;
|
||||
if (tipoAlerta == 'retrasos') _notificarRetrasosFallas = nuevoValor;
|
||||
});
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Mis Domicilios'),
|
||||
backgroundColor: Colors.green[700],
|
||||
foregroundColor: Colors.white,
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: TarjetaEtaWidget(
|
||||
horaInicio: '7:20 p.m.',
|
||||
horaFin: '7:35 p.m.',
|
||||
minutosRestantes: 15,
|
||||
estadoCamion: 'en_camino',
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: _misDomicilios.length,
|
||||
itemBuilder: (context, index) {
|
||||
final domicilio = _misDomicilios[index];
|
||||
return ListTile(
|
||||
leading: const Icon(Icons.location_on, color: Colors.green),
|
||||
title: Text(domicilio.etiqueta),
|
||||
subtitle: Text(domicilio.direccion),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton(
|
||||
onPressed: () => _abrirAjustesYFormulario(context),
|
||||
backgroundColor: Colors.green[700],
|
||||
child: const Icon(Icons.settings, color: Colors.white),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
228
lib/login.dart
Normal file
228
lib/login.dart
Normal file
@@ -0,0 +1,228 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'domicilios.dart'; // Para navegar aquí tras el login
|
||||
|
||||
class LoginScreen extends StatefulWidget {
|
||||
const LoginScreen({super.key});
|
||||
|
||||
@override
|
||||
State<LoginScreen> createState() => _LoginScreenState();
|
||||
}
|
||||
|
||||
class _LoginScreenState extends State<LoginScreen> with SingleTickerProviderStateMixin {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
|
||||
// Controladores para capturar el texto
|
||||
final _usuarioController = TextEditingController();
|
||||
final _passwordController = TextEditingController();
|
||||
|
||||
bool _obscurePassword = true; // Ocultar/mostrar contraseña
|
||||
late TabController _tabController; // Controla si inicia con Email o Teléfono
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_tabController = TabController(length: 2, vsync: this);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_usuarioController.dispose();
|
||||
_passwordController.dispose();
|
||||
_tabController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _iniciarSesion() {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
// Aquí irá tu lógica futura con Firebase/Supabase
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(
|
||||
content: Text('¡Ingreso exitoso!'),
|
||||
backgroundColor: Colors.green,
|
||||
),
|
||||
);
|
||||
|
||||
// Navegamos directamente a tu pantalla de Gestión de Domicilios
|
||||
Navigator.pushReplacement(
|
||||
context,
|
||||
MaterialPageRoute(builder: (context) => const GestionDomiciliosScreen()),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
body: SafeArea(
|
||||
child: SingleChildScrollView(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 16.0),
|
||||
child: Form(
|
||||
key: _formKey,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: [
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// Icono e Identidad de la App
|
||||
CircleAvatar(
|
||||
radius: 45,
|
||||
backgroundColor: Colors.green[50],
|
||||
child: Icon(Icons.recycling_rounded, size: 55, color: Colors.green[700]),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'EcoRecolección',
|
||||
style: Theme.of(context).textTheme.headlineMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.green[800],
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'Por una comunidad más limpia y educada',
|
||||
style: TextStyle(color: Colors.grey[600], fontSize: 14),
|
||||
),
|
||||
const SizedBox(height: 40),
|
||||
|
||||
// Selector de tipo de ingreso (Email / Teléfono)
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: TabBar(
|
||||
controller: _tabController,
|
||||
indicatorSize: TabBarIndicatorSize.tab,
|
||||
dividerColor: Colors.transparent,
|
||||
indicator: BoxDecoration(
|
||||
color: Colors.green[700],
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
labelColor: Colors.white,
|
||||
unselectedLabelColor: Colors.grey[600],
|
||||
labelStyle: const TextStyle(fontWeight: FontWeight.bold),
|
||||
tabs: const [
|
||||
Tab(text: 'Correo Electrónico'),
|
||||
Tab(text: 'Teléfono'),
|
||||
],
|
||||
onTap: (index) {
|
||||
_usuarioController.clear(); // Limpia al cambiar de pestaña
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Contenedor dinámico según el Tab activo
|
||||
AnimatedBuilder(
|
||||
animation: _tabController,
|
||||
builder: (context, child) {
|
||||
bool esEmail = _tabController.index == 0;
|
||||
return TextFormField(
|
||||
controller: _usuarioController,
|
||||
keyboardType: esEmail ? TextInputType.emailAddress : TextInputType.phone,
|
||||
decoration: InputDecoration(
|
||||
labelText: esEmail ? 'Correo Electrónico' : 'Número de Teléfono',
|
||||
hintText: esEmail ? 'ejemplo@correo.com' : '10 dígitos',
|
||||
prefixIcon: Icon(esEmail ? Icons.email_outlined : Icons.phone_android_rounded, color: Colors.green[700]),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.green[700]!, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.trim().isEmpty) {
|
||||
return esEmail ? 'Ingresa tu correo' : 'Ingresa tu teléfono';
|
||||
}
|
||||
if (esEmail && !RegExp(r'^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$').hasMatch(value)) {
|
||||
return 'Introduce un correo válido';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Campo de Contraseña
|
||||
TextFormField(
|
||||
controller: _passwordController,
|
||||
obscureText: _obscurePassword,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Contraseña',
|
||||
prefixIcon: Icon(Icons.lock_outline_rounded, color: Colors.green[700]),
|
||||
suffixIcon: IconButton(
|
||||
icon: Icon(_obscurePassword ? Icons.visibility_off_outlined : Icons.visibility_outlined, color: Colors.grey),
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_obscurePassword = !_obscurePassword;
|
||||
});
|
||||
},
|
||||
),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(12)),
|
||||
focusedBorder: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
borderSide: BorderSide(color: Colors.green[700]!, width: 2),
|
||||
),
|
||||
),
|
||||
validator: (value) {
|
||||
if (value == null || value.isEmpty) {
|
||||
return 'Ingresa tu contraseña';
|
||||
}
|
||||
if (value.length < 6) {
|
||||
return 'Debe tener al menos 6 caracteres';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
),
|
||||
|
||||
// Olvidé mi contraseña
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: TextButton(
|
||||
onPressed: () {},
|
||||
child: Text('¿Olvidaste tu contraseña?', style: TextStyle(color: Colors.green[800], fontWeight: FontWeight.w600)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
|
||||
// Botón Ingresar
|
||||
SizedBox(
|
||||
width: double.infinity,
|
||||
height: 52,
|
||||
child: ElevatedButton(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: Colors.green[700],
|
||||
foregroundColor: Colors.white,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||
elevation: 1,
|
||||
),
|
||||
onPressed: _iniciarSesion,
|
||||
child: const Text('Iniciar Sesión', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Crear cuenta nueva
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Text('¿No tienes una cuenta? ', style: TextStyle(color: Colors.grey[600])),
|
||||
GestureDetector(
|
||||
onTap: () {}, // Aquí abrirías la pantalla de registro
|
||||
child: Text(
|
||||
'Regístrate',
|
||||
style: TextStyle(color: Colors.green[800], fontWeight: FontWeight.bold, decoration: TextDecoration.underline),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
28
lib/main.dart
Normal file
28
lib/main.dart
Normal file
@@ -0,0 +1,28 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'login.dart'; // Importamos la nueva pantalla de Login
|
||||
|
||||
void main() {
|
||||
runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatelessWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MaterialApp(
|
||||
title: 'EcoRecolección App',
|
||||
debugShowCheckedModeBanner: false,
|
||||
theme: ThemeData(
|
||||
colorScheme: ColorScheme.fromSeed(
|
||||
seedColor: Colors.green,
|
||||
primary: Colors.green[700],
|
||||
),
|
||||
useMaterial3: true,
|
||||
),
|
||||
// Configuramos la app para que arranque directo en el Login
|
||||
home: const LoginScreen(),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
53
lib/notificaciones_service.dart
Normal file
53
lib/notificaciones_service.dart
Normal file
@@ -0,0 +1,53 @@
|
||||
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
|
||||
|
||||
class NotificacionesService {
|
||||
// Instancia única (Singleton)
|
||||
static final NotificacionesService _instance = NotificacionesService._internal();
|
||||
factory NotificacionesService() => _instance;
|
||||
NotificacionesService._internal();
|
||||
|
||||
final FlutterLocalNotificationsPlugin _localNotificationsPlugin = FlutterLocalNotificationsPlugin();
|
||||
|
||||
// Inicializa el sistema de alertas del teléfono
|
||||
Future<void> inicializarNotificaciones() async {
|
||||
const AndroidInitializationSettings androidSettings =
|
||||
AndroidInitializationSettings('@mipmap/ic_launcher'); // Icono por defecto de tu app Android
|
||||
|
||||
const InitializationSettings initSettings = InitializationSettings(
|
||||
android: androidSettings,
|
||||
);
|
||||
|
||||
// SOLUCIÓN: En las versiones actuales se debe pasar como argumento con nombre 'settings:'
|
||||
await _localNotificationsPlugin.initialize(
|
||||
initSettings,
|
||||
// Si en un futuro necesitas reaccionar cuando el usuario presiona la notificación:
|
||||
// onDidReceiveNotificationResponse: (NotificationResponse response) { ... }
|
||||
);
|
||||
}
|
||||
// Método genérico para disparar la alerta nativa en Android/iOS
|
||||
Future<void> mostrarNotificacionPush({
|
||||
required int id,
|
||||
required String titulo,
|
||||
required String mensaje,
|
||||
}) async {
|
||||
const AndroidNotificationDetails androidDetails = AndroidNotificationDetails(
|
||||
'canal_alertas_operativas', // ID del canal
|
||||
'Alertas Operativas Camión', // Nombre del canal visible para el usuario
|
||||
channelDescription: 'Avisos de rutas, aproximaciones e imprevistos mecánicos',
|
||||
importance: Importance.max,
|
||||
priority: Priority.high,
|
||||
playSound: true,
|
||||
);
|
||||
|
||||
const NotificationDetails platformDetails = NotificationDetails(
|
||||
android: androidDetails,
|
||||
);
|
||||
|
||||
await _localNotificationsPlugin.show(
|
||||
id,
|
||||
titulo,
|
||||
mensaje,
|
||||
platformDetails,
|
||||
);
|
||||
}
|
||||
}
|
||||
183
lib/panel_configuracion_bottom_sheet.dart
Normal file
183
lib/panel_configuracion_bottom_sheet.dart
Normal file
@@ -0,0 +1,183 @@
|
||||
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,
|
||||
activeColor: 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,
|
||||
activeColor: 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,
|
||||
activeColor: Colors.green[700],
|
||||
onChanged: (bool value) {
|
||||
setState(() => _retrasosFallas = value);
|
||||
widget.onAlertasChanged(value, 'retrasos');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
114
lib/tarjetaeta.dart
Normal file
114
lib/tarjetaeta.dart
Normal file
@@ -0,0 +1,114 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class TarjetaEtaWidget extends StatelessWidget {
|
||||
final String horaInicio;
|
||||
final String horaFin;
|
||||
final int minutosRestantes;
|
||||
final String estadoCamion;
|
||||
|
||||
const TarjetaEtaWidget({
|
||||
super.key,
|
||||
required this.horaInicio,
|
||||
required this.horaFin,
|
||||
required this.minutosRestantes,
|
||||
required this.estadoCamion,
|
||||
});
|
||||
|
||||
Color _obtenerColorEstado() {
|
||||
return estadoCamion == 'retrasado' ? Colors.amber[700]! : Colors.green[700]!;
|
||||
}
|
||||
|
||||
String _generarMensajeAccion() {
|
||||
if (estadoCamion == 'retrasado') {
|
||||
return 'El servicio presenta un ligero retraso por tráfico.';
|
||||
}
|
||||
if (minutosRestantes <= 5) {
|
||||
return '¡Saca tus residuos clasificados ahora mismo!';
|
||||
}
|
||||
return 'Prepara tus bolsas de residuos orgánicos e inorgánicos.';
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final Color colorTema = _obtenerColorEstado();
|
||||
|
||||
return Card(
|
||||
elevation: 3,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
colorTema.withOpacity(0.05),
|
||||
colorTema.withOpacity(0.12),
|
||||
],
|
||||
),
|
||||
),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.local_shipping_rounded, color: colorTema, size: 24),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
estadoCamion == 'retrasado' ? 'Estado: Demorado' : 'Ruta en Progreso',
|
||||
style: TextStyle(
|
||||
color: colorTema,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 13,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(color: colorTema, shape: BoxShape.circle),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'Llega en aproximadamente $minutosRestantes minutos',
|
||||
style: Theme.of(context).textTheme.titleMedium?.copyWith(
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.grey[800],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
'El camión llegará a tu zona entre las $horaInicio y las $horaFin.',
|
||||
style: TextStyle(fontSize: 14, color: Colors.grey[700]),
|
||||
),
|
||||
const Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 10.0),
|
||||
child: Divider(color: Colors.black),
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.info_outline_rounded, color: colorTema, size: 18),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(
|
||||
_generarMensajeAccion(),
|
||||
style: TextStyle(
|
||||
color: colorTema,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user