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,414 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
|
||||
// Comentario explicativo: Pantalla de Estado de Comunicación y Diagnóstico de Enlaces.
|
||||
// Reemplaza el firewall genérico por una consola especializada de telemetría de red y enlaces
|
||||
// (Canal IP/Fibra, Respaldo Celular 4G/LTE, Túnel VPN MikroTik y Heartbeats). Permite verificar
|
||||
// de inmediato por qué un panel de alarmas no reporta antes de despachar soporte técnico.
|
||||
class ComunicacionPage extends StatefulWidget {
|
||||
final int? clienteIdInicial;
|
||||
|
||||
const ComunicacionPage({Key? key, this.clienteIdInicial}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<ComunicacionPage> createState() => _ComunicacionPageState();
|
||||
}
|
||||
|
||||
class _ComunicacionPageState extends State<ComunicacionPage> {
|
||||
String _filtroEstado = 'todos'; // todos | online | advertencia | desconectado
|
||||
final Map<int, bool> _probandoEnlace = {};
|
||||
|
||||
final List<Map<String, dynamic>> _enlaces = [
|
||||
{
|
||||
'id': 101,
|
||||
'cliente': 'Banco Metropolitano - Sede Central',
|
||||
'ip': '192.168.10.201',
|
||||
'canalPrincipal': 'Fibra Óptica Dedicada (Ethernet)',
|
||||
'canalPrincipalEstado': 'online',
|
||||
'canalRespaldo': 'Módem 4G LTE Banda 28',
|
||||
'canalRespaldoEstado': 'online',
|
||||
'senalRssi': '-68 dBm (Excelente)',
|
||||
'latencia': '18 ms',
|
||||
'ultimoHeartbeat': 'Hace 12 seg',
|
||||
'estadoGeneral': 'online',
|
||||
'tunelVpn': 'WireGuard CHR #01 (Activo)',
|
||||
'firewallDrops': '0 drops',
|
||||
},
|
||||
{
|
||||
'id': 102,
|
||||
'cliente': 'Centro Comercial Gran Plaza',
|
||||
'ip': '192.168.10.205',
|
||||
'canalPrincipal': 'Enlace IP Corporativo',
|
||||
'canalPrincipalEstado': 'online',
|
||||
'canalRespaldo': 'SIM 4G Multicarrier',
|
||||
'canalRespaldoEstado': 'advertencia',
|
||||
'senalRssi': '-89 dBm (Señal Débil)',
|
||||
'latencia': '42 ms',
|
||||
'ultimoHeartbeat': 'Hace 45 seg',
|
||||
'estadoGeneral': 'advertencia',
|
||||
'tunelVpn': 'WireGuard CHR #02 (Activo)',
|
||||
'firewallDrops': '2 reintentos',
|
||||
},
|
||||
{
|
||||
'id': 103,
|
||||
'cliente': 'Torre Empresarial Sigma',
|
||||
'ip': '192.168.10.210',
|
||||
'canalPrincipal': 'FTTH Red Local',
|
||||
'canalPrincipalEstado': 'online',
|
||||
'canalRespaldo': 'Backup Celular M2M',
|
||||
'canalRespaldoEstado': 'online',
|
||||
'senalRssi': '-74 dBm (Buena)',
|
||||
'latencia': '24 ms',
|
||||
'ultimoHeartbeat': 'Hace 20 seg',
|
||||
'estadoGeneral': 'online',
|
||||
'tunelVpn': 'SSTP MikroTik (Activo)',
|
||||
'firewallDrops': '0 drops',
|
||||
},
|
||||
{
|
||||
'id': 104,
|
||||
'cliente': 'Almacenes El Ahorro - Sucursal Norte',
|
||||
'ip': '192.168.10.215',
|
||||
'canalPrincipal': 'ADSL Cobre (Intermitente)',
|
||||
'canalPrincipalEstado': 'desconectado',
|
||||
'canalRespaldo': 'GPRS 2G/3G Antiguo',
|
||||
'canalRespaldoEstado': 'desconectado',
|
||||
'senalRssi': 'Sin señal',
|
||||
'latencia': 'Timeout (>3000 ms)',
|
||||
'ultimoHeartbeat': 'Hace 38 min (FALLO TEST 24H)',
|
||||
'estadoGeneral': 'desconectado',
|
||||
'tunelVpn': 'Túnel caído (Handshake expirado)',
|
||||
'firewallDrops': '14 paquetes bloqueados / NAT timeout',
|
||||
},
|
||||
];
|
||||
|
||||
// Comentario explicativo: Realiza un ping y test de diagnóstico en vivo hacia el canal de comunicación del cliente
|
||||
Future<void> _ejecutarDiagnostico(int id, String cliente) async {
|
||||
setState(() => _probandoEnlace[id] = true);
|
||||
await Future.delayed(const Duration(seconds: 2));
|
||||
if (!mounted) return;
|
||||
setState(() => _probandoEnlace[id] = false);
|
||||
|
||||
final enlace = _enlaces.firstWhere((e) => e['id'] == id);
|
||||
final esCaido = enlace['estadoGeneral'] == 'desconectado';
|
||||
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: esCaido ? AppColors.alarmaActiva : AppColors.surfaceHigh,
|
||||
content: Row(
|
||||
children: [
|
||||
Icon(esCaido ? Icons.error_outline : Icons.check_circle,
|
||||
color: esCaido ? Colors.white : AppColors.clienteOk, size: 18),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
esCaido
|
||||
? 'Fallo de enlace: El panel de $cliente no responde por IP ni Respaldo Celular.'
|
||||
: 'Diagnóstico OK: $cliente respondió con latencia de ${enlace['latencia']}.',
|
||||
style: appLabel(color: Colors.white, weight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final enlacesFiltrados = _filtroEstado == 'todos'
|
||||
? _enlaces
|
||||
: _enlaces.where((e) => e['estadoGeneral'] == _filtroEstado).toList();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Header
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text('Estado de Comunicación y Enlaces Perimetrales',
|
||||
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('TELEMETRÍA RED',
|
||||
style: appLabel(size: 10, weight: FontWeight.bold, color: AppColors.primary)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text('Supervisión de canales IP, respaldo celular 4G, túneles VPN y diagnóstico ante alarmas sin reporte',
|
||||
style: appLabel(size: 12, color: AppColors.outline)),
|
||||
],
|
||||
),
|
||||
// Filtro por estado
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
_filtroChip('todos', 'Todos'),
|
||||
_filtroChip('online', 'En Línea'),
|
||||
_filtroChip('advertencia', 'Degradados'),
|
||||
_filtroChip('desconectado', 'Caídos'),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Tarjetas KPI de Red
|
||||
Row(
|
||||
children: [
|
||||
_buildKpiCard('Total Enlaces Monitoreados', '${_enlaces.length}', Icons.router_outlined, AppColors.primary),
|
||||
const SizedBox(width: 14),
|
||||
_buildKpiCard('Operando 100% en Línea',
|
||||
'${_enlaces.where((e) => e['estadoGeneral'] == 'online').length}', Icons.check_circle_outlined, AppColors.clienteOk),
|
||||
const SizedBox(width: 14),
|
||||
_buildKpiCard('Enlace Degradado / Respaldo',
|
||||
'${_enlaces.where((e) => e['estadoGeneral'] == 'advertencia').length}', Icons.warning_amber_rounded, AppColors.clienteAlerta),
|
||||
const SizedBox(width: 14),
|
||||
_buildKpiCard('Paneles Sin Comunicación',
|
||||
'${_enlaces.where((e) => e['estadoGeneral'] == 'desconectado').length}', Icons.portable_wifi_off, AppColors.alarmaActiva),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
|
||||
// Lista de Canales por Cliente
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
itemCount: enlacesFiltrados.length,
|
||||
itemBuilder: (ctx, i) => _buildTarjetaEnlace(enlacesFiltrados[i]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _filtroChip(String estado, String label) {
|
||||
final activo = _filtroEstado == estado;
|
||||
return InkWell(
|
||||
onTap: () => setState(() => _filtroEstado = estado),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
color: activo ? AppColors.primaryContainer : Colors.transparent,
|
||||
child: Text(
|
||||
label,
|
||||
style: appLabel(
|
||||
size: 11,
|
||||
weight: activo ? FontWeight.bold : FontWeight.normal,
|
||||
color: activo ? AppColors.primary : AppColors.outline,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildKpiCard(String titulo, String valor, IconData icono, Color color) {
|
||||
return Expanded(
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(14),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: color.withOpacity(0.12),
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: Icon(icono, color: color, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(valor, style: appHeadline(size: 18, weight: FontWeight.w800, color: AppColors.onSurface)),
|
||||
Text(titulo, style: appLabel(size: 11, color: AppColors.outline)),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildTarjetaEnlace(Map<String, dynamic> e) {
|
||||
final id = e['id'] as int;
|
||||
final probando = _probandoEnlace[id] == true;
|
||||
final estado = e['estadoGeneral'] as String;
|
||||
final esCaido = estado == 'desconectado';
|
||||
final esDegradado = estado == 'advertencia';
|
||||
|
||||
Color colorBorde = AppColors.outlineVariant;
|
||||
if (esCaido) colorBorde = AppColors.alarmaActiva;
|
||||
if (esDegradado) colorBorde = AppColors.clienteAlerta;
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 12),
|
||||
padding: const EdgeInsets.all(18),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: colorBorde, width: (esCaido || esDegradado) ? 1.5 : 1.0),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
width: 10,
|
||||
height: 10,
|
||||
decoration: BoxDecoration(
|
||||
color: esCaido ? AppColors.alarmaActiva : (esDegradado ? AppColors.clienteAlerta : AppColors.clienteOk),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Text(e['cliente'],
|
||||
style: appHeadline(size: 15, weight: FontWeight.w700, color: AppColors.onSurface)),
|
||||
const SizedBox(width: 10),
|
||||
Text('IP: ${e['ip']}', style: appLabel(size: 12, color: AppColors.outline)),
|
||||
],
|
||||
),
|
||||
// Botón de test de comunicación
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
foregroundColor: AppColors.primary,
|
||||
side: const BorderSide(color: AppColors.outlineVariant),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 10),
|
||||
),
|
||||
icon: probando
|
||||
? const SizedBox(
|
||||
width: 14,
|
||||
height: 14,
|
||||
child: CircularProgressIndicator(strokeWidth: 2, color: AppColors.primary),
|
||||
)
|
||||
: const Icon(Icons.network_ping, size: 16),
|
||||
label: Text(probando ? 'Probando...' : 'Diagnóstico en Vivo',
|
||||
style: appLabel(size: 11, weight: FontWeight.bold)),
|
||||
onPressed: probando ? null : () => _ejecutarDiagnostico(id, e['cliente']),
|
||||
),
|
||||
],
|
||||
),
|
||||
const Divider(height: 20, color: AppColors.outlineVariant),
|
||||
// Canales y Métricas de Conectividad
|
||||
Row(
|
||||
children: [
|
||||
// Canal Principal
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Canal Principal:', style: appLabel(size: 10, color: AppColors.outline)),
|
||||
const SizedBox(height: 2),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.settings_ethernet,
|
||||
size: 14,
|
||||
color: e['canalPrincipalEstado'] == 'online' ? AppColors.clienteOk : AppColors.alarmaActiva),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text(e['canalPrincipal'],
|
||||
style: appLabel(size: 12, color: AppColors.onSurface, weight: FontWeight.w600),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Canal Respaldo Celular
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Respaldo Celular (SIM):', style: appLabel(size: 10, color: AppColors.outline)),
|
||||
const SizedBox(height: 2),
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.signal_cellular_alt,
|
||||
size: 14,
|
||||
color: e['canalRespaldoEstado'] == 'online' ? AppColors.clienteOk : AppColors.clienteAlerta),
|
||||
const SizedBox(width: 6),
|
||||
Expanded(
|
||||
child: Text('${e['canalRespaldo']} • ${e['senalRssi']}',
|
||||
style: appLabel(size: 12, color: AppColors.onSurface, weight: FontWeight.w600),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Túnel VPN y Latencia
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Túnel VPN & Latencia:', style: appLabel(size: 10, color: AppColors.outline)),
|
||||
const SizedBox(height: 2),
|
||||
Text('${e['tunelVpn']} (${e['latencia']})',
|
||||
style: appLabel(size: 12, color: AppColors.primary, weight: FontWeight.w600),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Último Heartbeat
|
||||
Expanded(
|
||||
flex: 2,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Último Heartbeat / Drops:', style: appLabel(size: 10, color: AppColors.outline)),
|
||||
const SizedBox(height: 2),
|
||||
Text('${e['ultimoHeartbeat']} • ${e['firewallDrops']}',
|
||||
style: appLabel(
|
||||
size: 11,
|
||||
color: esCaido ? AppColors.alarmaActiva : AppColors.outline,
|
||||
weight: esCaido ? FontWeight.bold : FontWeight.normal,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user