Co-authored-by: eddgranados12 <eddgranados12@users.noreply.github.com>
Co-authored-by: MENDOZA BALLARDO GAEL RICARDO <gael-meb123@users.noreply.github.com> Co-authored-by: Azareth-Tr <Azareth-Tr@users.noreply.github.com> modificacion de vistas panel admin, login, animaciones y implementacion de mascota
This commit is contained in:
@@ -67,6 +67,38 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
),
|
||||
];
|
||||
|
||||
final List<String> _rutas = [
|
||||
'Ruta Norte',
|
||||
'Ruta Sur',
|
||||
];
|
||||
|
||||
final List<ReportModel> _reportes = [
|
||||
ReportModel(
|
||||
id: 'report-01',
|
||||
truckId: 'truck-01',
|
||||
titulo: 'Reporte de ruta bloqueada',
|
||||
descripcion: 'El camión no puede continuar porque la ruta está obstruida.',
|
||||
fecha: DateTime.now().subtract(Duration(hours: 2)),
|
||||
estado: 'Pendiente',
|
||||
),
|
||||
ReportModel(
|
||||
id: 'report-02',
|
||||
truckId: 'truck-01',
|
||||
titulo: 'Revisión mecánica urgente',
|
||||
descripcion: 'Se detectó una fuga de aceite en el motor.',
|
||||
fecha: DateTime.now().subtract(Duration(days: 1, hours: 3)),
|
||||
estado: 'En revisión',
|
||||
),
|
||||
ReportModel(
|
||||
id: 'report-03',
|
||||
truckId: 'truck-02',
|
||||
titulo: 'Retraso en servicio',
|
||||
descripcion: 'El camión llegó tarde por un problema en la carretera.',
|
||||
fecha: DateTime.now().subtract(Duration(hours: 5)),
|
||||
estado: 'Resuelto',
|
||||
),
|
||||
];
|
||||
|
||||
void _selectSection(int index) {
|
||||
setState(() => _selectedSection = index);
|
||||
}
|
||||
@@ -82,6 +114,9 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
case 2:
|
||||
_showTruckForm();
|
||||
break;
|
||||
case 3:
|
||||
_showRouteForm();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -244,7 +279,29 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
children: [
|
||||
_buildTextField('Placa', placa),
|
||||
const SizedBox(height: 12),
|
||||
_buildTextField('Ruta', ruta),
|
||||
if (_rutas.isNotEmpty)
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: _rutas.contains(ruta.text) ? ruta.text : _rutas.first,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Ruta',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
),
|
||||
),
|
||||
items: _rutas
|
||||
.map((rutaName) => DropdownMenuItem(
|
||||
value: rutaName,
|
||||
child: Text(rutaName),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
ruta.text = value;
|
||||
}
|
||||
},
|
||||
)
|
||||
else
|
||||
_buildTextField('Ruta', ruta),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: conductorId,
|
||||
@@ -318,6 +375,293 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
void _showRouteForm({String? ruta}) {
|
||||
final nombreRuta = TextEditingController(text: ruta ?? '');
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return AlertDialog(
|
||||
title: Text(ruta == null ? 'Agregar ruta' : 'Editar ruta'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusLg),
|
||||
),
|
||||
content: Form(
|
||||
key: formKey,
|
||||
child: _buildTextField('Nombre de la ruta', nombreRuta),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (!formKey.currentState!.validate()) return;
|
||||
final nuevoNombre = nombreRuta.text.trim();
|
||||
setState(() {
|
||||
if (ruta == null) {
|
||||
_rutas.add(nuevoNombre);
|
||||
} else {
|
||||
final index = _rutas.indexOf(ruta);
|
||||
if (index != -1) {
|
||||
_rutas[index] = nuevoNombre;
|
||||
for (var i = 0; i < _camiones.length; i++) {
|
||||
if (_camiones[i].ruta == ruta) {
|
||||
_camiones[i] = TruckModel(
|
||||
id: _camiones[i].id,
|
||||
placa: _camiones[i].placa,
|
||||
ruta: nuevoNombre,
|
||||
conductorId: _camiones[i].conductorId,
|
||||
activo: _camiones[i].activo,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < _conductores.length; i++) {
|
||||
if (_conductores[i].rutaAsignada == ruta) {
|
||||
_conductores[i] = DriverModel(
|
||||
id: _conductores[i].id,
|
||||
nombre: _conductores[i].nombre,
|
||||
telefono: _conductores[i].telefono,
|
||||
placa: _conductores[i].placa,
|
||||
rutaAsignada: nuevoNombre,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
child: const Text('Guardar'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
void _showReportForm({ReportModel? reporte}) {
|
||||
final titulo = TextEditingController(text: reporte?.titulo ?? '');
|
||||
final descripcion = TextEditingController(text: reporte?.descripcion ?? '');
|
||||
String selectedTruckId = reporte?.truckId ?? _camiones.first.id;
|
||||
final formKey = GlobalKey<FormState>();
|
||||
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return StatefulBuilder(
|
||||
builder: (ctx, setStateDialog) {
|
||||
return AlertDialog(
|
||||
title: Text(reporte == null ? 'Agregar reporte' : 'Editar reporte'),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusLg),
|
||||
),
|
||||
content: Form(
|
||||
key: formKey,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: selectedTruckId,
|
||||
decoration: InputDecoration(
|
||||
labelText: 'Unidad',
|
||||
border: OutlineInputBorder(
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
),
|
||||
),
|
||||
items: _camiones
|
||||
.map((truck) => DropdownMenuItem(
|
||||
value: truck.id,
|
||||
child: Text('${truck.placa} · ${truck.ruta}'),
|
||||
))
|
||||
.toList(),
|
||||
onChanged: (value) {
|
||||
if (value != null) {
|
||||
setStateDialog(() => selectedTruckId = value);
|
||||
}
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
_buildTextField('Título', titulo),
|
||||
const SizedBox(height: 12),
|
||||
_buildTextField('Descripción', descripcion),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(ctx),
|
||||
child: const Text('Cancelar'),
|
||||
),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (!formKey.currentState!.validate()) return;
|
||||
final nuevo = ReportModel(
|
||||
id: reporte?.id ?? 'report-${DateTime.now().millisecondsSinceEpoch}',
|
||||
truckId: selectedTruckId,
|
||||
titulo: titulo.text.trim(),
|
||||
descripcion: descripcion.text.trim(),
|
||||
fecha: DateTime.now(),
|
||||
);
|
||||
setState(() {
|
||||
if (reporte == null) {
|
||||
_reportes.add(nuevo);
|
||||
} else {
|
||||
final index = _reportes.indexWhere((r) => r.id == reporte.id);
|
||||
if (index != -1) {
|
||||
_reportes[index] = nuevo;
|
||||
}
|
||||
}
|
||||
});
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
child: const Text('Guardar'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildReportSection() {
|
||||
final header = Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 4),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
const Text(
|
||||
'Reportes de unidades',
|
||||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w700),
|
||||
),
|
||||
TextButton.icon(
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('Agregar reporte'),
|
||||
onPressed: _showReportForm,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
if (_camiones.isEmpty) {
|
||||
return Column(
|
||||
children: [
|
||||
header,
|
||||
const SizedBox(height: 10),
|
||||
const Expanded(child: Center(child: Text('No hay unidades registradas.'))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
final Map<String, List<ReportModel>> reportesPorUnidad = {
|
||||
for (var camion in _camiones) camion.id: [],
|
||||
};
|
||||
for (var reporte in _reportes) {
|
||||
reportesPorUnidad[reporte.truckId]?.add(reporte);
|
||||
}
|
||||
|
||||
final unidadesOrdenadas = List<TruckModel>.from(_camiones)
|
||||
..sort((a, b) => a.placa.compareTo(b.placa));
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
header,
|
||||
const SizedBox(height: 10),
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
children: unidadesOrdenadas.map((camion) {
|
||||
final reportes = reportesPorUnidad[camion.id] ?? [];
|
||||
reportes.sort((a, b) => b.fecha.compareTo(a.fecha));
|
||||
|
||||
return w.AppCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(camion.placa,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
)),
|
||||
const SizedBox(height: 6),
|
||||
Text(camion.ruta,
|
||||
style: const TextStyle(color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
w.StatusBadge.gray('${reportes.length} reporte(s)'),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
if (reportes.isEmpty)
|
||||
const Text('No hay reportes para esta unidad.',
|
||||
style: TextStyle(color: AppTheme.textSecondary))
|
||||
else
|
||||
Column(
|
||||
children: reportes
|
||||
.map((reporte) => Padding(
|
||||
padding: const EdgeInsets.only(top: 12),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppTheme.surface,
|
||||
borderRadius: BorderRadius.circular(AppTheme.radiusMd),
|
||||
border: Border.all(color: AppTheme.border),
|
||||
),
|
||||
padding: const EdgeInsets.all(12),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(reporte.titulo,
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
fontWeight: FontWeight.w700,
|
||||
)),
|
||||
),
|
||||
Text(reporte.fechaFormateada,
|
||||
style: const TextStyle(
|
||||
fontSize: 12,
|
||||
color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(reporte.descripcion,
|
||||
style: const TextStyle(color: AppTheme.textSecondary)),
|
||||
const SizedBox(height: 8),
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: w.StatusBadge.amber(reporte.estado),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
))
|
||||
.toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}).toList(),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTextField(String label, TextEditingController controller,
|
||||
{TextInputType keyboardType = TextInputType.text}) {
|
||||
return TextFormField(
|
||||
@@ -352,7 +696,33 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
setState(() => lista.remove(item));
|
||||
setState(() {
|
||||
lista.remove(item);
|
||||
if (item is String && identical(lista, _rutas)) {
|
||||
for (var i = 0; i < _camiones.length; i++) {
|
||||
if (_camiones[i].ruta == item) {
|
||||
_camiones[i] = TruckModel(
|
||||
id: _camiones[i].id,
|
||||
placa: _camiones[i].placa,
|
||||
ruta: '',
|
||||
conductorId: _camiones[i].conductorId,
|
||||
activo: _camiones[i].activo,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < _conductores.length; i++) {
|
||||
if (_conductores[i].rutaAsignada == item) {
|
||||
_conductores[i] = DriverModel(
|
||||
id: _conductores[i].id,
|
||||
nombre: _conductores[i].nombre,
|
||||
telefono: _conductores[i].telefono,
|
||||
placa: _conductores[i].placa,
|
||||
rutaAsignada: '',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
style: TextButton.styleFrom(foregroundColor: AppTheme.danger),
|
||||
@@ -402,7 +772,13 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
return Scaffold(
|
||||
backgroundColor: AppTheme.background,
|
||||
appBar: AppBar(
|
||||
title: Text(_currentTab == 0 ? 'Mi perfil' : 'Panel administrador'),
|
||||
title: Text(
|
||||
_currentTab == 0
|
||||
? 'Mi perfil'
|
||||
: _currentTab == 1
|
||||
? 'Panel administrador'
|
||||
: 'Reportes por unidad',
|
||||
),
|
||||
actions: _currentTab == 1
|
||||
? [
|
||||
IconButton(
|
||||
@@ -411,13 +787,22 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
tooltip: 'Agregar',
|
||||
),
|
||||
]
|
||||
: null,
|
||||
: _currentTab == 2
|
||||
? [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.add),
|
||||
onPressed: _showReportForm,
|
||||
tooltip: 'Agregar reporte',
|
||||
),
|
||||
]
|
||||
: null,
|
||||
),
|
||||
body: IndexedStack(
|
||||
index: _currentTab,
|
||||
children: [
|
||||
_buildAdminProfile(),
|
||||
_buildAdminBody(),
|
||||
_buildReportSection(),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: BottomNavigationBar(
|
||||
@@ -432,6 +817,10 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
icon: Icon(Icons.admin_panel_settings_outlined),
|
||||
label: 'Admin',
|
||||
),
|
||||
BottomNavigationBarItem(
|
||||
icon: Icon(Icons.report_problem_outlined),
|
||||
label: 'Reportes',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -448,6 +837,7 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
_buildSectionButton('Usuarios', 0),
|
||||
_buildSectionButton('Conductores', 1),
|
||||
_buildSectionButton('Camiones', 2),
|
||||
_buildSectionButton('Rutas', 3),
|
||||
],
|
||||
),
|
||||
),
|
||||
@@ -576,11 +966,74 @@ class _AdminScreenState extends State<AdminScreen> {
|
||||
return _buildUsuarioSection();
|
||||
case 1:
|
||||
return _buildDriverSection();
|
||||
default:
|
||||
case 2:
|
||||
return _buildTruckSection();
|
||||
case 3:
|
||||
return _buildRouteSection();
|
||||
default:
|
||||
return _buildReportSection();
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildRouteSection() {
|
||||
if (_rutas.isEmpty) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Text('No hay rutas registradas.'),
|
||||
const SizedBox(height: 12),
|
||||
ElevatedButton(
|
||||
onPressed: _showRouteForm,
|
||||
child: const Text('Agregar ruta'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
return ListView.builder(
|
||||
padding: const EdgeInsets.only(bottom: 16),
|
||||
itemCount: _rutas.length,
|
||||
itemBuilder: (context, index) {
|
||||
final ruta = _rutas[index];
|
||||
final asignados = _camiones.where((camion) => camion.ruta == ruta).length;
|
||||
return w.AppCard(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(ruta,
|
||||
style: const TextStyle(
|
||||
fontSize: 15,
|
||||
fontWeight: FontWeight.w700,
|
||||
)),
|
||||
const SizedBox(height: 6),
|
||||
Text('$asignados camión(es) asignado(s)',
|
||||
style: const TextStyle(color: AppTheme.textSecondary)),
|
||||
],
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.edit_outlined),
|
||||
onPressed: () => _showRouteForm(ruta: ruta),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.delete_outline, color: AppTheme.danger),
|
||||
onPressed: () {
|
||||
_confirmDelete(ruta, _rutas, 'ruta');
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildUsuarioSection() {
|
||||
if (_usuarios.isEmpty) {
|
||||
return const Center(child: Text('No hay usuarios registrados.'));
|
||||
|
||||
Reference in New Issue
Block a user