137 lines
5.3 KiB
Dart
137 lines
5.3 KiB
Dart
import 'package:flutter/material.dart';
|
|
import '../theme.dart';
|
|
import '../db/dao/incidentes_dao.dart';
|
|
|
|
// Comentario explicativo: Pantalla de Incidentes conectada a IncidentesDao.
|
|
// Permite auditar y revisar el registro de incidentes locales y sincronizados,
|
|
// garantizando que el revisor de la tienda observe datos coherentes y completos.
|
|
class IncidentesPage extends StatefulWidget {
|
|
const IncidentesPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<IncidentesPage> createState() => _IncidentesPageState();
|
|
}
|
|
|
|
class _IncidentesPageState extends State<IncidentesPage> {
|
|
final _incidentesDao = IncidentesDao();
|
|
List<Map<String, dynamic>> _incidentes = [];
|
|
bool _cargando = true;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_cargarIncidentes();
|
|
}
|
|
|
|
Future<void> _cargarIncidentes() async {
|
|
final lista = await _incidentesDao.getRecientes(limit: 50);
|
|
if (!mounted) return;
|
|
setState(() {
|
|
_incidentes = lista;
|
|
_cargando = false;
|
|
});
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SingleChildScrollView(
|
|
primary: false,
|
|
padding: const EdgeInsets.all(24),
|
|
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
|
Text('Registro de Incidentes',
|
|
style: appHeadline(size: 22, weight: FontWeight.w800, color: AppColors.onSurface)),
|
|
const SizedBox(height: 4),
|
|
Text('Bitácora de despacho de patrullas y respuesta a alarmas',
|
|
style: appLabel(size: 13, color: AppColors.outline)),
|
|
]),
|
|
IconButton(
|
|
icon: const Icon(Icons.refresh, color: AppColors.primary),
|
|
onPressed: _cargarIncidentes,
|
|
tooltip: 'Refrescar bitácora',
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 20),
|
|
|
|
if (_cargando)
|
|
const Center(child: CircularProgressIndicator())
|
|
else if (_incidentes.isEmpty)
|
|
Container(
|
|
padding: const EdgeInsets.all(32),
|
|
alignment: Alignment.center,
|
|
child: Text('No hay incidentes registrados.', style: appLabel(color: AppColors.outline)),
|
|
)
|
|
else
|
|
ListView.separated(
|
|
shrinkWrap: true,
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
itemCount: _incidentes.length,
|
|
separatorBuilder: (_, __) => const SizedBox(height: 12),
|
|
itemBuilder: (_, i) {
|
|
final inc = _incidentes[i];
|
|
final resuelto = (inc['resuelto'] as int? ?? 0) == 1;
|
|
|
|
return Container(
|
|
padding: const EdgeInsets.all(16),
|
|
decoration: BoxDecoration(
|
|
color: AppColors.surfaceLow,
|
|
borderRadius: BorderRadius.circular(12),
|
|
border: Border.all(
|
|
color: resuelto ? AppColors.clienteOk.withOpacity(0.3) : AppColors.alarmaActiva.withOpacity(0.4),
|
|
),
|
|
),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
Expanded(
|
|
child: Text(
|
|
inc['cliente_nombre'] as String? ?? 'Cliente',
|
|
style: appHeadline(size: 14, weight: FontWeight.w700, color: AppColors.onSurface),
|
|
),
|
|
),
|
|
Container(
|
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
|
decoration: BoxDecoration(
|
|
color: resuelto ? const Color(0xFF1B382B) : const Color(0xFF381B1B),
|
|
borderRadius: BorderRadius.circular(6),
|
|
),
|
|
child: Text(
|
|
resuelto ? 'RESUELTO' : 'EN ATENCIÓN',
|
|
style: appLabel(
|
|
size: 10,
|
|
weight: FontWeight.bold,
|
|
color: resuelto ? AppColors.clienteOk : AppColors.alarmaActiva,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
const SizedBox(height: 6),
|
|
Text(
|
|
'Tipo: ${(inc['tipo'] as String? ?? 'N/A').replaceAll('_', ' ').toUpperCase()} • Operador: ${inc['operador'] ?? 'Central'}',
|
|
style: appLabel(size: 12, color: AppColors.outline),
|
|
),
|
|
if (inc['notas'] != null && (inc['notas'] as String).isNotEmpty) ...[
|
|
const SizedBox(height: 8),
|
|
Text(
|
|
inc['notas'] as String,
|
|
style: appLabel(size: 12, color: AppColors.onSurfaceVariant),
|
|
),
|
|
],
|
|
],
|
|
),
|
|
);
|
|
},
|
|
),
|
|
]),
|
|
);
|
|
}
|
|
}
|