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,768 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
// Comentario explicativo: Importamos CacheClientesDao para persistir nuevos clientes agregados desde monitoreo de cámaras en la base de datos SQLite
|
||||
import '../db/dao/cache_clientes_dao.dart';
|
||||
|
||||
// Comentario explicativo: Pantalla de Cámaras y Video-verificación CCTV.
|
||||
// Expone grilla de monitoreo en vivo (1x1, 2x2, 3x3) para cámaras Hikvision ISAPI y Tuya IoT,
|
||||
// permitiendo a los operadores verificar visualmente si una intrusión es real antes del despacho.
|
||||
class CamarasPage extends StatefulWidget {
|
||||
const CamarasPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<CamarasPage> createState() => _CamarasPageState();
|
||||
}
|
||||
|
||||
class _CamarasPageState extends State<CamarasPage> {
|
||||
final _clientesDao = CacheClientesDao();
|
||||
int _cuadricula = 4; // 1, 4 (2x2), 9 (3x3)
|
||||
int? _camaraSeleccionada;
|
||||
String _filtroCliente = 'todos';
|
||||
List<String> _listaClientes = [
|
||||
'todos',
|
||||
'Banco Metropolitano',
|
||||
'Centro Comercial Gran Plaza',
|
||||
'Torre Empresarial Sigma',
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_cargarClientesDb();
|
||||
}
|
||||
|
||||
// Comentario explicativo: Carga los clientes desde la base de datos SQLite y los unifica con los clientes de las cámaras
|
||||
Future<void> _cargarClientesDb() async {
|
||||
try {
|
||||
final clientesDb = await _clientesDao.getTodos();
|
||||
final setNombres = <String>{'todos'};
|
||||
for (final cam in _camaras) {
|
||||
final cli = cam['cliente'] as String?;
|
||||
if (cli != null && cli.isNotEmpty) setNombres.add(cli);
|
||||
}
|
||||
for (final c in clientesDb) {
|
||||
final nom = c['nombre'] as String?;
|
||||
if (nom != null && nom.isNotEmpty) setNombres.add(nom);
|
||||
}
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
_listaClientes = setNombres.toList();
|
||||
});
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
// Canales de cámaras simulados / en vivo
|
||||
final List<Map<String, dynamic>> _camaras = [
|
||||
{
|
||||
'id': 1,
|
||||
'nombre': 'CAM 01 - Bóveda Principal',
|
||||
'cliente': 'Banco Metropolitano',
|
||||
'zona': 'Bóveda Subterránea',
|
||||
'ip': '192.168.10.201',
|
||||
'estado': 'online',
|
||||
'fps': 25,
|
||||
'resolucion': '4K (3840x2160)',
|
||||
'tipo': 'Hikvision ISAPI PTZ',
|
||||
'conAlarma': true,
|
||||
},
|
||||
{
|
||||
'id': 2,
|
||||
'nombre': 'CAM 02 - Acceso Principal Peatonal',
|
||||
'cliente': 'Banco Metropolitano',
|
||||
'zona': 'Lobby Entrada',
|
||||
'ip': '192.168.10.202',
|
||||
'estado': 'online',
|
||||
'fps': 30,
|
||||
'resolucion': '1080p (1920x1080)',
|
||||
'tipo': 'Hikvision Domo IR',
|
||||
'conAlarma': false,
|
||||
},
|
||||
{
|
||||
'id': 3,
|
||||
'nombre': 'CAM 03 - Pasillo Central Comercial',
|
||||
'cliente': 'Centro Comercial Gran Plaza',
|
||||
'zona': 'Pasillo Nivel 1',
|
||||
'ip': '192.168.10.205',
|
||||
'estado': 'online',
|
||||
'fps': 20,
|
||||
'resolucion': '1080p (1920x1080)',
|
||||
'tipo': 'Tuya Smart Bullet',
|
||||
'conAlarma': true,
|
||||
},
|
||||
{
|
||||
'id': 4,
|
||||
'nombre': 'CAM 04 - Estacionamiento Subterráneo',
|
||||
'cliente': 'Centro Comercial Gran Plaza',
|
||||
'zona': 'Sótano -2',
|
||||
'ip': '192.168.10.206',
|
||||
'estado': 'online',
|
||||
'fps': 25,
|
||||
'resolucion': '1080p (1920x1080)',
|
||||
'tipo': 'Hikvision ISAPI LPR',
|
||||
'conAlarma': false,
|
||||
},
|
||||
{
|
||||
'id': 5,
|
||||
'nombre': 'CAM 05 - Recepción y Molinetes',
|
||||
'cliente': 'Torre Empresarial Sigma',
|
||||
'zona': 'Ingreso Torre A',
|
||||
'ip': '192.168.10.210',
|
||||
'estado': 'online',
|
||||
'fps': 30,
|
||||
'resolucion': '2K (2560x1440)',
|
||||
'tipo': 'Hikvision Reconocimiento Facial',
|
||||
'conAlarma': false,
|
||||
},
|
||||
{
|
||||
'id': 6,
|
||||
'nombre': 'CAM 06 - Perímetro Posterior',
|
||||
'cliente': 'Torre Empresarial Sigma',
|
||||
'zona': 'Cerca Perimetral',
|
||||
'ip': '192.168.10.211',
|
||||
'estado': 'offline',
|
||||
'fps': 0,
|
||||
'resolucion': 'Sin señal',
|
||||
'tipo': 'Tuya Smart Térmica',
|
||||
'conAlarma': false,
|
||||
},
|
||||
];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final camarasVisibles = _filtroCliente == 'todos'
|
||||
? _camaras
|
||||
: _camaras.where((c) => c['cliente'] == _filtroCliente).toList();
|
||||
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(24),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// Barra de controles de video-verificación
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Text('Video-Verificación y Circuito Cerrado (CCTV)',
|
||||
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: const Color(0xFF1B382B),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
),
|
||||
child: Text('LIVE STREAM',
|
||||
style: appLabel(size: 10, weight: FontWeight.bold, color: AppColors.clienteOk)),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text('Feeds en vivo Hikvision ISAPI y Tuya Smart IoT con soporte de snapshot y PTZ',
|
||||
style: appLabel(size: 12, color: AppColors.outline)),
|
||||
],
|
||||
),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
// Selector de layout de cuadrícula
|
||||
Container(
|
||||
height: 38,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
_btnLayout(1, Icons.crop_square),
|
||||
_btnLayout(4, Icons.grid_view),
|
||||
_btnLayout(9, Icons.grid_on),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
// Comentario explicativo: Columna que ubica el botón de agregar (+add) en la parte superior del select de clientes
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
// Botón (+add) para registrar un nuevo cliente desde la vista de cámaras
|
||||
InkWell(
|
||||
onTap: _mostrarDialogoNuevoCliente,
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 4),
|
||||
margin: const EdgeInsets.only(bottom: 6),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryContainer.withValues(alpha: 0.4),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
border: Border.all(color: AppColors.primary.withValues(alpha: 0.5)),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.add_circle, size: 14, color: AppColors.primary),
|
||||
const SizedBox(width: 5),
|
||||
Text(
|
||||
'(+add) Agregar Cliente',
|
||||
style: appLabel(size: 11, weight: FontWeight.w700, color: AppColors.primary),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
// Dropdown dinámico para filtrar por cliente seleccionado
|
||||
Container(
|
||||
height: 38,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: _listaClientes.contains(_filtroCliente) ? _filtroCliente : 'todos',
|
||||
dropdownColor: AppColors.surfaceHigh,
|
||||
style: appLabel(size: 12, color: AppColors.onSurface),
|
||||
items: _listaClientes.map((nombre) {
|
||||
return DropdownMenuItem(
|
||||
value: nombre,
|
||||
child: Text(nombre == 'todos' ? 'Todos los clientes' : nombre),
|
||||
);
|
||||
}).toList(),
|
||||
onChanged: (v) {
|
||||
if (v != null) setState(() => _filtroCliente = v);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 20),
|
||||
|
||||
// Grilla de Cámaras
|
||||
Expanded(
|
||||
child: _cuadricula == 1 && _camaraSeleccionada != null
|
||||
? _buildVistaDetallada(
|
||||
_camaras.firstWhere((c) => c['id'] == _camaraSeleccionada, orElse: () => _camaras.first))
|
||||
: GridView.builder(
|
||||
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: _cuadricula == 1 ? 1 : (_cuadricula == 4 ? 2 : 3),
|
||||
crossAxisSpacing: 14,
|
||||
mainAxisSpacing: 14,
|
||||
childAspectRatio: 16 / 10,
|
||||
),
|
||||
itemCount: camarasVisibles.length,
|
||||
itemBuilder: (ctx, i) => _buildTarjetaCamara(camarasVisibles[i]),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Botón selector de disposición de cuadrícula de video (1x1, 2x2, 3x3)
|
||||
Widget _btnLayout(int count, IconData icono) {
|
||||
final activo = _cuadricula == count;
|
||||
return InkWell(
|
||||
onTap: () => setState(() => _cuadricula = count),
|
||||
borderRadius: BorderRadius.circular(6),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
color: activo ? AppColors.primaryContainer : Colors.transparent,
|
||||
child: Icon(icono, size: 18, color: activo ? AppColors.primary : AppColors.outline),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Tarjeta de cámara individual con overlay de estado, alarma y datos de stream
|
||||
Widget _buildTarjetaCamara(Map<String, dynamic> cam) {
|
||||
final conAlarma = cam['conAlarma'] == true;
|
||||
final online = cam['estado'] == 'online';
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
setState(() {
|
||||
_cuadricula = 1;
|
||||
_camaraSeleccionada = cam['id'] as int;
|
||||
});
|
||||
},
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF0F141A),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
border: Border.all(
|
||||
color: conAlarma ? AppColors.alarmaActiva : AppColors.outlineVariant,
|
||||
width: conAlarma ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
// Feed simulado
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(
|
||||
online ? Icons.videocam : Icons.videocam_off_outlined,
|
||||
size: 40,
|
||||
color: online ? (conAlarma ? AppColors.alarmaActiva : AppColors.outline) : AppColors.error,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
online ? 'CANAL EN VIVO RTSP' : 'SEÑAL PERDIDA (OFFLINE)',
|
||||
style: appLabel(
|
||||
size: 11,
|
||||
weight: FontWeight.bold,
|
||||
color: online ? AppColors.outline : AppColors.error,
|
||||
),
|
||||
),
|
||||
if (online)
|
||||
Text('${cam['resolucion']} @ ${cam['fps']} FPS',
|
||||
style: appLabel(size: 10, color: AppColors.outlineVariant)),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Header con nombre de cámara y badge
|
||||
Positioned(
|
||||
top: 10,
|
||||
left: 12,
|
||||
right: 12,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(cam['nombre'],
|
||||
style: appHeadline(size: 13, weight: FontWeight.w700, color: Colors.white),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
Text('${cam['cliente']} • ${cam['zona']}',
|
||||
style: appLabel(size: 10, color: Colors.white70),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis),
|
||||
],
|
||||
),
|
||||
),
|
||||
if (conAlarma)
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.alarmaActiva,
|
||||
borderRadius: BorderRadius.circular(4),
|
||||
),
|
||||
child: Text('ALARMA', style: appLabel(size: 9, weight: FontWeight.bold, color: Colors.white)),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Barra inferior con IP y tipo de cámara
|
||||
Positioned(
|
||||
bottom: 8,
|
||||
left: 12,
|
||||
right: 12,
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(cam['ip'], style: appLabel(size: 10, color: Colors.white54)),
|
||||
Text(cam['tipo'], style: appLabel(size: 10, color: Colors.white54)),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Vista de cámara ampliada en pantalla completa con controles de paneo, zoom y snapshot
|
||||
Widget _buildVistaDetallada(Map<String, dynamic> cam) {
|
||||
return Column(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.surfaceLow,
|
||||
foregroundColor: AppColors.onSurface,
|
||||
side: const BorderSide(color: AppColors.outlineVariant),
|
||||
),
|
||||
icon: const Icon(Icons.arrow_back, size: 16),
|
||||
label: Text('Volver a cuadrícula', style: appLabel(size: 12)),
|
||||
onPressed: () => setState(() => _cuadricula = 4),
|
||||
),
|
||||
Text('${cam['nombre']} (${cam['cliente']})',
|
||||
style: appHeadline(size: 16, weight: FontWeight.w700, color: AppColors.onSurface)),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.camera_alt_outlined, color: AppColors.primary, size: 20),
|
||||
tooltip: 'Tomar instantánea (Snapshot)',
|
||||
onPressed: () {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
content: Text('Instantánea capturada y guardada en auditoría.', style: appLabel()),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.videocam_outlined, color: AppColors.clienteOk, size: 20),
|
||||
tooltip: 'Grabación manual',
|
||||
onPressed: () {},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Expanded(
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color: const Color(0xFF0A0E14),
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
const Icon(Icons.videocam, size: 80, color: AppColors.outline),
|
||||
const SizedBox(height: 12),
|
||||
Text('STREAM EN DIRECTO RTSP / ISAPI HIKVISION',
|
||||
style: appHeadline(size: 14, color: AppColors.onSurfaceVariant)),
|
||||
const SizedBox(height: 4),
|
||||
Text('${cam['resolucion']} • Protocolo Seguro H.265+',
|
||||
style: appLabel(size: 12, color: AppColors.outline)),
|
||||
],
|
||||
),
|
||||
),
|
||||
// Controles PTZ virtuales sobreimpresos
|
||||
Positioned(
|
||||
bottom: 20,
|
||||
right: 20,
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.black.withValues(alpha: 0.7),
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
border: Border.all(color: Colors.white24),
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
IconButton(icon: const Icon(Icons.arrow_drop_up, color: Colors.white), onPressed: () {}),
|
||||
Row(
|
||||
children: [
|
||||
IconButton(icon: const Icon(Icons.arrow_left, color: Colors.white), onPressed: () {}),
|
||||
const Icon(Icons.control_camera, color: AppColors.primary, size: 20),
|
||||
IconButton(icon: const Icon(Icons.arrow_right, color: Colors.white), onPressed: () {}),
|
||||
],
|
||||
),
|
||||
IconButton(icon: const Icon(Icons.arrow_drop_down, color: Colors.white), onPressed: () {}),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// Comentario explicativo: Abre un diálogo modal para registrar un nuevo cliente y asociarle un canal de cámara CCTV
|
||||
Future<void> _mostrarDialogoNuevoCliente() async {
|
||||
final clienteCtrl = TextEditingController();
|
||||
final camaraCtrl = TextEditingController(text: 'CAM 0${_camaras.length + 1} - Entrada Principal');
|
||||
final zonaCtrl = TextEditingController(text: 'Acceso Peatonal');
|
||||
final ipCtrl = TextEditingController(text: '192.168.10.${212 + _camaras.length}');
|
||||
String servicio = 'CCTV / Video-vigilancia';
|
||||
String tipoCam = 'Hikvision ISAPI PTZ';
|
||||
const resolucion = '1080p (1920x1080)';
|
||||
bool conAlarma = false;
|
||||
|
||||
await showDialog(
|
||||
context: context,
|
||||
builder: (ctx) {
|
||||
return StatefulBuilder(
|
||||
builder: (dialogCtx, setDialogState) {
|
||||
return AlertDialog(
|
||||
backgroundColor: AppColors.surface,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
side: const BorderSide(color: AppColors.outlineVariant),
|
||||
),
|
||||
title: Row(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryContainer,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
),
|
||||
child: const Icon(Icons.videocam, color: AppColors.primary, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text('Agregar Cliente / Feed CCTV',
|
||||
style: appHeadline(size: 16, weight: FontWeight.bold, color: AppColors.onSurface)),
|
||||
],
|
||||
),
|
||||
content: SizedBox(
|
||||
width: 480,
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Nombre del Cliente / Empresa *', style: appLabel(size: 12, weight: FontWeight.w600, color: AppColors.onSurface)),
|
||||
const SizedBox(height: 6),
|
||||
TextField(
|
||||
controller: clienteCtrl,
|
||||
style: appLabel(color: AppColors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Ej. Corporación Andina / Edificio Central',
|
||||
hintStyle: appLabel(color: AppColors.outline),
|
||||
filled: true,
|
||||
fillColor: AppColors.surfaceLow,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: const BorderSide(color: AppColors.outlineVariant)),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Text('Tipo de Servicio Asociado', style: appLabel(size: 12, weight: FontWeight.w600, color: AppColors.onSurface)),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: servicio,
|
||||
isExpanded: true,
|
||||
dropdownColor: AppColors.surfaceHigh,
|
||||
style: appLabel(size: 13, color: AppColors.onSurface),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'CCTV / Video-vigilancia', child: Text('CCTV / Video-vigilancia')),
|
||||
DropdownMenuItem(value: 'Monitoreo de Alarmas', child: Text('Monitoreo de Alarmas')),
|
||||
DropdownMenuItem(value: 'Rastreo Satelital GPS', child: Text('Rastreo Satelital GPS')),
|
||||
DropdownMenuItem(value: 'Control de Acceso', child: Text('Control de Acceso')),
|
||||
DropdownMenuItem(value: 'Servicio Integral 360', child: Text('Servicio Integral 360')),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) setDialogState(() => servicio = v);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Nombre de Cámara', style: appLabel(size: 12, weight: FontWeight.w600, color: AppColors.onSurface)),
|
||||
const SizedBox(height: 6),
|
||||
TextField(
|
||||
controller: camaraCtrl,
|
||||
style: appLabel(color: AppColors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: AppColors.surfaceLow,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: const BorderSide(color: AppColors.outlineVariant)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Zona / Sede', style: appLabel(size: 12, weight: FontWeight.w600, color: AppColors.onSurface)),
|
||||
const SizedBox(height: 6),
|
||||
TextField(
|
||||
controller: zonaCtrl,
|
||||
style: appLabel(color: AppColors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: AppColors.surfaceLow,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: const BorderSide(color: AppColors.outlineVariant)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 14),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('IP de Cámara / Host ISAPI', style: appLabel(size: 12, weight: FontWeight.w600, color: AppColors.onSurface)),
|
||||
const SizedBox(height: 6),
|
||||
TextField(
|
||||
controller: ipCtrl,
|
||||
style: appLabel(color: AppColors.onSurface),
|
||||
decoration: InputDecoration(
|
||||
filled: true,
|
||||
fillColor: AppColors.surfaceLow,
|
||||
contentPadding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10),
|
||||
border: OutlineInputBorder(borderRadius: BorderRadius.circular(8), borderSide: const BorderSide(color: AppColors.outlineVariant)),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text('Tecnología / Marca', style: appLabel(size: 12, weight: FontWeight.w600, color: AppColors.onSurface)),
|
||||
const SizedBox(height: 6),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.surfaceLow,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: AppColors.outlineVariant),
|
||||
),
|
||||
child: DropdownButtonHideUnderline(
|
||||
child: DropdownButton<String>(
|
||||
value: tipoCam,
|
||||
isExpanded: true,
|
||||
dropdownColor: AppColors.surfaceHigh,
|
||||
style: appLabel(size: 11, color: AppColors.onSurface),
|
||||
items: const [
|
||||
DropdownMenuItem(value: 'Hikvision ISAPI PTZ', child: Text('Hikvision PTZ')),
|
||||
DropdownMenuItem(value: 'Hikvision Domo IR', child: Text('Hikvision Domo')),
|
||||
DropdownMenuItem(value: 'Tuya Smart Bullet', child: Text('Tuya Bullet')),
|
||||
DropdownMenuItem(value: 'Hikvision ISAPI LPR', child: Text('Hikvision LPR')),
|
||||
DropdownMenuItem(value: 'Tuya Smart Térmica', child: Text('Tuya Térmica')),
|
||||
],
|
||||
onChanged: (v) {
|
||||
if (v != null) setDialogState(() => tipoCam = v);
|
||||
},
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
CheckboxListTile(
|
||||
value: conAlarma,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
title: Text('Vincular con alarma activa inmediata', style: appLabel(size: 12, color: AppColors.onSurface)),
|
||||
subtitle: Text('Simula un disparo perimetral en la zona de video para pruebas de verificación', style: appLabel(size: 10, color: AppColors.outline)),
|
||||
onChanged: (val) {
|
||||
setDialogState(() => conAlarma = val ?? false);
|
||||
},
|
||||
activeColor: AppColors.alarmaActiva,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogCtx),
|
||||
child: Text('Cancelar', style: appLabel(color: AppColors.outline)),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: AppColors.primary,
|
||||
foregroundColor: const Color(0xFF002F6C),
|
||||
),
|
||||
icon: const Icon(Icons.add, size: 16),
|
||||
label: const Text('Guardar Cliente'),
|
||||
onPressed: () async {
|
||||
final nombre = clienteCtrl.text.trim();
|
||||
if (nombre.isEmpty) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
const SnackBar(content: Text('Por favor ingresa el nombre del cliente.')),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Comentario explicativo: Registrar cliente en la base de datos SQLite local
|
||||
final nuevoId = await _clientesDao.obtenerSiguienteId();
|
||||
await _clientesDao.insertar({
|
||||
'id': nuevoId,
|
||||
'nombre': nombre,
|
||||
'estado': conAlarma ? 'alerta' : 'normal',
|
||||
'alarmas_activas': conAlarma ? 1 : 0,
|
||||
'alarmas_criticas': 0,
|
||||
'tipo_servicio': servicio,
|
||||
'ultima_actualizacion': DateTime.now().toIso8601String(),
|
||||
});
|
||||
|
||||
// Comentario explicativo: Insertar nueva cámara en el listado reactivo de video
|
||||
final nuevaCam = {
|
||||
'id': _camaras.length + 1,
|
||||
'nombre': camaraCtrl.text.trim().isNotEmpty ? camaraCtrl.text.trim() : 'CAM - $nombre',
|
||||
'cliente': nombre,
|
||||
'zona': zonaCtrl.text.trim().isNotEmpty ? zonaCtrl.text.trim() : 'Sede Principal',
|
||||
'ip': ipCtrl.text.trim().isNotEmpty ? ipCtrl.text.trim() : '192.168.10.220',
|
||||
'estado': 'online',
|
||||
'fps': 25,
|
||||
'resolucion': resolucion,
|
||||
'tipo': tipoCam,
|
||||
'conAlarma': conAlarma,
|
||||
};
|
||||
|
||||
setState(() {
|
||||
_camaras.add(nuevaCam);
|
||||
_filtroCliente = nombre;
|
||||
});
|
||||
|
||||
await _cargarClientesDb();
|
||||
if (mounted) {
|
||||
Navigator.pop(dialogCtx);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
content: Text('Cliente "$nombre" y canal de cámara registrados con éxito.',
|
||||
style: appLabel(color: AppColors.clienteOk)),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user