feat: submenu tactico (camaras, rastreo OSM/CartoDB), comunicacion, consola datos SQLite, clientes tipo_servicio y documentacion estandar
This commit is contained in:
@@ -0,0 +1,544 @@
|
||||
import 'package:flutter/material.dart';
|
||||
// Comentario explicativo: Importación de flutter_map y latlong2 para integración de cartografía real basada en OpenStreetMap (OSM) y CartoDB
|
||||
import 'package:flutter_map/flutter_map.dart';
|
||||
import 'package:latlong2/latlong.dart';
|
||||
import '../theme.dart';
|
||||
|
||||
// Comentario explicativo: Pantalla de Rastreo y Despacho Táctico con mapa cartográfico real OpenStreetMap / CartoDB.
|
||||
// Ofrece geolocalización satelital precisa de sedes monitoreadas, centrado automático de cámara,
|
||||
// seguimiento de patrullas móviles en ruta y conmutación de capas (Modo Oscuro SOC / OSM Estándar).
|
||||
class RastreoPage extends StatefulWidget {
|
||||
const RastreoPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<RastreoPage> createState() => _RastreoPageState();
|
||||
}
|
||||
|
||||
class _RastreoPageState extends State<RastreoPage> {
|
||||
final MapController _mapController = MapController();
|
||||
String _filtroTipo = 'todos'; // todos | sedes | patrullas
|
||||
int? _seleccionadoId;
|
||||
bool _modoOscuro = true; // true: CartoDB Dark Matter, false: OpenStreetMap Standard
|
||||
|
||||
// Puntos de interés y unidades con coordenadas reales en Quito, Ecuador
|
||||
final List<Map<String, dynamic>> _puntos = [
|
||||
{
|
||||
'id': 101,
|
||||
'tipo': 'sede',
|
||||
'nombre': 'Banco Metropolitano - Sede Central',
|
||||
'direccion': 'Av. Amazonas y Naciones Unidas',
|
||||
'lat': -0.1806,
|
||||
'lng': -78.4842,
|
||||
'estado': 'critica',
|
||||
'alarmaActiva': 'Pánico SOS en Bóveda',
|
||||
'operador': 'Operador Demo',
|
||||
},
|
||||
{
|
||||
'id': 102,
|
||||
'tipo': 'sede',
|
||||
'nombre': 'Centro Comercial Gran Plaza',
|
||||
'direccion': 'Av. 6 de Diciembre y Eloy Alfaro',
|
||||
'lat': -0.1912,
|
||||
'lng': -78.4790,
|
||||
'estado': 'alerta',
|
||||
'alarmaActiva': 'Sensor PIR Pasillo 1',
|
||||
'operador': 'Carlos Mendoza',
|
||||
},
|
||||
{
|
||||
'id': 103,
|
||||
'tipo': 'sede',
|
||||
'nombre': 'Torre Empresarial Sigma',
|
||||
'direccion': 'Av. República y Shyris',
|
||||
'lat': -0.1850,
|
||||
'lng': -78.4810,
|
||||
'estado': 'normal',
|
||||
'alarmaActiva': null,
|
||||
'operador': null,
|
||||
},
|
||||
{
|
||||
'id': 201,
|
||||
'tipo': 'patrulla',
|
||||
'nombre': 'Patrulla Móvil Alfa-1',
|
||||
'conductor': 'Sgt. Gómez / Cbo. Paredes',
|
||||
'vehiculo': 'Camioneta Blindada #12',
|
||||
'lat': -0.1830,
|
||||
'lng': -78.4825,
|
||||
'velocidad': '48 km/h',
|
||||
'rumbo': 'NE hacia Sede Central',
|
||||
'estado': 'en_despacho',
|
||||
'bateria': 94,
|
||||
'ultimaTransmision': 'Hace 5 seg',
|
||||
},
|
||||
{
|
||||
'id': 202,
|
||||
'tipo': 'patrulla',
|
||||
'nombre': 'Patrulla Móvil Bravo-2',
|
||||
'conductor': 'Guardia Téc. Morales',
|
||||
'vehiculo': 'Motocicleta Táctica #04',
|
||||
'lat': -0.1918,
|
||||
'lng': -78.4785,
|
||||
'velocidad': '0 km/h (Punto Fijo)',
|
||||
'rumbo': 'Perímetro Gran Plaza',
|
||||
'estado': 'disponible',
|
||||
'bateria': 88,
|
||||
'ultimaTransmision': 'Hace 12 seg',
|
||||
},
|
||||
{
|
||||
'id': 203,
|
||||
'tipo': 'patrulla',
|
||||
'nombre': 'Unidad Táctica Charlie-3',
|
||||
'conductor': 'Sup. Rivas',
|
||||
'vehiculo': 'Patrulla Rápida #07',
|
||||
'lat': -0.1872,
|
||||
'lng': -78.4835,
|
||||
'velocidad': '32 km/h',
|
||||
'rumbo': 'Ronda de Prevención',
|
||||
'estado': 'disponible',
|
||||
'bateria': 76,
|
||||
'ultimaTransmision': 'Hace 8 seg',
|
||||
},
|
||||
];
|
||||
|
||||
// Comentario explicativo: Centra suavemente la cámara del mapa sobre las coordenadas del elemento seleccionado
|
||||
void _centrarEn(double lat, double lng, int id) {
|
||||
setState(() => _seleccionadoId = id);
|
||||
_mapController.move(LatLng(lat, lng), 16.0);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final filtrados = _filtroTipo == 'todos'
|
||||
? _puntos
|
||||
: _puntos.where((p) => p['tipo'] == _filtroTipo).toList();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header con selector de segmento y conmutador de capas de mapa
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text('Rastreo y Mapa Táctico de Despacho',
|
||||
style: appHeadline(size: 20, weight: FontWeight.w800, color: AppColors.onSurface)),
|
||||
const SizedBox(width: 10),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text(_modoOscuro ? 'MAPA OSCURO SOC' : 'OPENSTREETMAP',
|
||||
style: appLabel(size: 10, weight: FontWeight.bold, color: AppColors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text('Cartografía satelital real OpenStreetMap, posicionamiento GPS de sedes y patrullas de reacción',
|
||||
style: appLabel(size: 12, color: AppColors.outline)),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
children: [
|
||||
// Botón de alternar capa de mapa (Dark SOC / OSM Clásico)
|
||||
OutlinedButton.icon(
|
||||
style: OutlinedButton.styleFrom(
|
||||
foregroundColor: AppColors.onSurface,
|
||||
side: const BorderSide(color: AppColors.outlineVariant),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
),
|
||||
icon: Icon(_modoOscuro ? Icons.light_mode_outlined : Icons.dark_mode_outlined, size: 16),
|
||||
label: Text(_modoOscuro ? 'Ver OSM Estándar' : 'Ver Modo Oscuro SOC',
|
||||
style: appLabel(size: 11)),
|
||||
onPressed: () => setState(() => _modoOscuro = !_modoOscuro),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
// Segmented selector de tipo
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
_filtroBtn('todos', 'Todos'),
|
||||
_filtroBtn('sedes', 'Sedes Clientes'),
|
||||
_filtroBtn('patrullas', 'Patrullas GPS'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Contenedor principal: Mapa real OpenStreetMap a la izquierda + Panel de Unidades a la derecha
|
||||
Expanded(
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Mapa interactivo real basado en FlutterMap + OpenStreetMap
|
||||
Expanded(
|
||||
flex: 3,
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF0C1017),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
FlutterMap(
|
||||
mapController: _mapController,
|
||||
options: const MapOptions(
|
||||
initialCenter: LatLng(-0.1850, -78.4820),
|
||||
initialZoom: 14.5,
|
||||
minZoom: 5.0,
|
||||
maxZoom: 18.5,
|
||||
),
|
||||
children: [
|
||||
// Comentario explicativo: Capa de teselas (Tiles) de mapa real.
|
||||
// Modo Oscuro: CartoDB Dark Matter. Modo Claro: OpenStreetMap Tile Server estándar.
|
||||
TileLayer(
|
||||
urlTemplate: _modoOscuro
|
||||
? 'https://basemaps.cartocdn.com/rastertiles/dark_all/{z}/{x}/{y}.png'
|
||||
: 'https://tile.openstreetmap.org/{z}/{x}/{y}.png',
|
||||
userAgentPackageName: 'net.telcotronics.central_monitoreo',
|
||||
),
|
||||
// Comentario explicativo: Marcadores geográficos interactivos ubicados en coordenadas reales
|
||||
MarkerLayer(
|
||||
markers: filtrados.map((p) => _crearMarcador(p)).toList(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// Controles de zoom y centrado flotantes en el mapa
|
||||
Positioned(
|
||||
top: 16,
|
||||
right: 16,
|
||||
child: Column(
|
||||
children: [
|
||||
_btnControlMapa(Icons.add, 'Acercar Zoom', () {
|
||||
final zoom = _mapController.camera.zoom + 1;
|
||||
_mapController.move(_mapController.camera.center, zoom);
|
||||
}),
|
||||
const SizedBox(height: 6),
|
||||
_btnControlMapa(Icons.remove, 'Alejar Zoom', () {
|
||||
final zoom = _mapController.camera.zoom - 1;
|
||||
_mapController.move(_mapController.camera.center, zoom);
|
||||
}),
|
||||
const SizedBox(height: 10),
|
||||
_btnControlMapa(Icons.my_location, 'Centrar Vista General', () {
|
||||
_mapController.move(const LatLng(-0.1850, -78.4820), 14.5);
|
||||
}),
|
||||
const SizedBox(height: 6),
|
||||
_btnControlMapa(Icons.warning_amber_rounded, 'Centrar en Pánico Activo', () {
|
||||
_mapController.move(const LatLng(-0.1806, -78.4842), 16.5);
|
||||
setState(() => _seleccionadoId = 101);
|
||||
}),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
// Leyenda de colores del mapa en esquina inferior izquierda
|
||||
Positioned(
|
||||
bottom: 16,
|
||||
left: 16,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow.withOpacity(0.92),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
_leyendaItem(AppColors.alarmaActiva, 'Sede con Pánico / Alarma'),
|
||||
const SizedBox(width: 14),
|
||||
_leyendaItem(AppColors.primary, 'Patrulla Móvil en Ruta'),
|
||||
const SizedBox(width: 14),
|
||||
_leyendaItem(AppColors.clienteOk, 'Unidad Disponible'),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 18),
|
||||
|
||||
// Panel lateral de lista y telemetría de unidades
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text('Unidades y Puntos de Interés',
|
||||
style: appHeadline(size: 14, weight: FontWeight.w700, color: AppColors.onSurface)),
|
||||
Text('${filtrados.length} puntos',
|
||||
style: appLabel(size: 11, color: AppColors.outline)),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text('Toca una unidad para centrar el mapa y visualizar su telemetría GPS',
|
||||
style: appLabel(size: 11, color: AppColors.outline)),
|
||||
const Divider(height: 20, color: AppColors.outlineVariant),
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: filtrados.length,
|
||||
itemBuilder: (ctx, i) {
|
||||
final p = filtrados[i];
|
||||
final esSeleccionado = _seleccionadoId == p['id'];
|
||||
final esPatrulla = p['tipo'] == 'patrulla';
|
||||
|
||||
return InkWell(
|
||||
onTap: () => _centrarEn(p['lat'] as double, p['lng'] as double, p['id'] as int),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.only(bottom: 8),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: esSeleccionado ? AppColors.surfaceHigh : AppColors.surfaceLowest,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: esSeleccionado ? AppColors.primary : AppColors.outlineVariant,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(
|
||||
esPatrulla ? Icons.directions_car : Icons.location_city,
|
||||
size: 16,
|
||||
color: esPatrulla ? AppColors.primary : AppColors.secondary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Text(p['nombre'],
|
||||
style: appHeadline(
|
||||
size: 12, weight: FontWeight.w700, color: AppColors.onSurface)),
|
||||
],
|
||||
),
|
||||
_badgeEstado(p),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
if (esPatrulla) ...[
|
||||
Text('Personal: ${p['conductor']}',
|
||||
style: appLabel(size: 11, color: AppColors.outline)),
|
||||
Text('Velocidad: ${p['velocidad']} • ${p['rumbo']}',
|
||||
style: appLabel(size: 11, color: AppColors.primary)),
|
||||
const SizedBox(height: 4),
|
||||
Row(
|
||||
children: [
|
||||
const Icon(Icons.battery_charging_full, size: 12, color: AppColors.clienteOk),
|
||||
const SizedBox(width: 4),
|
||||
Text('${p['bateria']}% Batería',
|
||||
style: appLabel(size: 10, color: AppColors.outline)),
|
||||
const SizedBox(width: 10),
|
||||
Text('Fix: ${p['ultimaTransmision']}',
|
||||
style: appLabel(size: 10, color: AppColors.outlineVariant)),
|
||||
const Spacer(),
|
||||
const Icon(Icons.gps_fixed, size: 12, color: AppColors.primary),
|
||||
const SizedBox(width: 2),
|
||||
Text('GPS', style: appLabel(size: 9, color: AppColors.primary)),
|
||||
],
|
||||
),
|
||||
] else ...[
|
||||
Text(p['direccion'], style: appLabel(size: 11, color: AppColors.outline)),
|
||||
if (p['alarmaActiva'] != null)
|
||||
Text('Alerta: ${p['alarmaActiva']}',
|
||||
style: appLabel(size: 11, color: AppColors.alarmaActiva)),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Genera un marcador Marker compatible con flutter_map 8.x
|
||||
Marker _crearMarcador(Map<String, dynamic> p) {
|
||||
final esPatrulla = p['tipo'] == 'patrulla';
|
||||
final id = p['id'] as int;
|
||||
final esSeleccionado = _seleccionadoId == id;
|
||||
final lat = p['lat'] as double;
|
||||
final lng = p['lng'] as double;
|
||||
|
||||
Color colorPin = AppColors.secondary;
|
||||
if (esPatrulla) {
|
||||
colorPin = AppColors.primary;
|
||||
} else {
|
||||
if (p['estado'] == 'critica') colorPin = AppColors.alarmaActiva;
|
||||
if (p['estado'] == 'alerta') colorPin = AppColors.clienteAlerta;
|
||||
}
|
||||
|
||||
return Marker(
|
||||
point: LatLng(lat, lng),
|
||||
width: 140,
|
||||
height: 70,
|
||||
alignment: Alignment.center,
|
||||
child: GestureDetector(
|
||||
onTap: () => _centrarEn(lat, lng, id),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withOpacity(0.85),
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
border: Border.all(color: esSeleccionado ? colorPin : Colors.white24),
|
||||
),
|
||||
child: Text(
|
||||
p['nombre'],
|
||||
style: appLabel(size: 9, color: Colors.white, weight: FontWeight.w600),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 2),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(7),
|
||||
decoration: BoxDecoration(
|
||||
color: colorPin,
|
||||
shape: BoxShape.circle,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: colorPin.withOpacity(0.4),
|
||||
blurRadius: 8,
|
||||
spreadRadius: 2,
|
||||
),
|
||||
],
|
||||
border: Border.all(color: Colors.white, width: esSeleccionado ? 2.0 : 1.0),
|
||||
),
|
||||
child: Icon(
|
||||
esPatrulla ? Icons.local_police : Icons.business,
|
||||
size: 15,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _btnControlMapa(IconData icono, String tooltip, VoidCallback onTap) {
|
||||
return Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow.withOpacity(0.9),
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: IconButton(
|
||||
icon: Icon(icono, size: 16, color: AppColors.onSurface),
|
||||
tooltip: tooltip,
|
||||
onPressed: onTap,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _filtroBtn(String tipo, String label) {
|
||||
final activo = _filtroTipo == tipo;
|
||||
return InkWell(
|
||||
onTap: () => setState(() => _filtroTipo = tipo),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 8),
|
||||
color: activo ? AppColors.primaryContainer : Colors.transparent,
|
||||
child: Text(
|
||||
label,
|
||||
style: appLabel(
|
||||
size: 12,
|
||||
weight: activo ? FontWeight.bold : FontWeight.normal,
|
||||
color: activo ? AppColors.primary : AppColors.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _leyendaItem(Color color, String texto) {
|
||||
return Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 8,
|
||||
height: 8,
|
||||
decoration: BoxDecoration(color: color, shape: BoxShape.circle),
|
||||
),
|
||||
const SizedBox(width: 6),
|
||||
Text(texto, style: appLabel(size: 10, color: AppColors.outline)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _badgeEstado(Map<String, dynamic> p) {
|
||||
final esPatrulla = p['tipo'] == 'patrulla';
|
||||
final estado = p['estado'] as String?;
|
||||
Color color = AppColors.clienteOk;
|
||||
String label = 'NORMAL';
|
||||
|
||||
if (esPatrulla) {
|
||||
if (estado == 'en_despacho') {
|
||||
color = AppColors.alarmaActiva;
|
||||
label = 'EN RUTA';
|
||||
} else {
|
||||
color = AppColors.clienteOk;
|
||||
label = 'DISPONIBLE';
|
||||
}
|
||||
} else {
|
||||
if (estado == 'critica') {
|
||||
color = AppColors.alarmaActiva;
|
||||
label = 'PÁNICO';
|
||||
} else if (estado == 'alerta') {
|
||||
color = AppColors.clienteAlerta;
|
||||
label = 'ALERTA';
|
||||
}
|
||||
}
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(color: color.withOpacity(0.15), borderRadius: BorderRadius.circular(4)),
|
||||
child: Text(label, style: appLabel(size: 9, weight: FontWeight.bold, color: color)),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user