From 885e84d176ea0ed93714984d31f5929f040ef86f Mon Sep 17 00:00:00 2001 From: Pablinux Date: Tue, 14 Apr 2026 00:44:46 -0500 Subject: [PATCH] feat: add monitoreo alarma page with dashboard and animations MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Página de monitoreo con tarjeta de estado animada (pulso), mini-stats, gráfico de frecuencia semanal, eventos críticos, registro de eventos con timeline y vista táctica con grid y ping animado. Co-Authored-By: Claude Sonnet 4.6 --- lib/pages/monitoreo_alarma_page.dart | 437 +++++++++++++++++++++++++++ 1 file changed, 437 insertions(+) create mode 100644 lib/pages/monitoreo_alarma_page.dart diff --git a/lib/pages/monitoreo_alarma_page.dart b/lib/pages/monitoreo_alarma_page.dart new file mode 100644 index 0000000..7e6a399 --- /dev/null +++ b/lib/pages/monitoreo_alarma_page.dart @@ -0,0 +1,437 @@ +import 'package:flutter/material.dart'; +import '../theme.dart'; + +class MonitoreoAlarmaPage extends StatefulWidget { + const MonitoreoAlarmaPage({Key? key}) : super(key: key); + + @override + State createState() => _MonitoreoAlarmaPageState(); +} + +class _MonitoreoAlarmaPageState extends State + with TickerProviderStateMixin { + + late final AnimationController _pulseCtrl; + late final AnimationController _pingCtrl; + late final Animation _pulseScale; + late final Animation _pulseGlow; + late final Animation _pingScale; + late final Animation _pingOpacity; + + @override + void initState() { + super.initState(); + + _pulseCtrl = AnimationController(vsync: this, + duration: const Duration(seconds: 2))..repeat(); + _pulseScale = TweenSequence([ + TweenSequenceItem(tween: Tween(begin: 0.95, end: 1.0), weight: 35), + TweenSequenceItem(tween: Tween(begin: 1.0, end: 0.95), weight: 65), + ]).animate(_pulseCtrl); + _pulseGlow = TweenSequence([ + TweenSequenceItem(tween: Tween(begin: 0.7, end: 0.0), weight: 70), + TweenSequenceItem(tween: Tween(begin: 0.0, end: 0.7), weight: 30), + ]).animate(_pulseCtrl); + + _pingCtrl = AnimationController(vsync: this, + duration: const Duration(milliseconds: 1200))..repeat(); + _pingScale = Tween(begin: 1.0, end: 2.8) + .animate(CurvedAnimation(parent: _pingCtrl, curve: Curves.easeOut)); + _pingOpacity = Tween(begin: 0.6, end: 0.0) + .animate(CurvedAnimation(parent: _pingCtrl, curve: Curves.easeOut)); + } + + @override + void dispose() { + _pulseCtrl.dispose(); + _pingCtrl.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SingleChildScrollView( + padding: const EdgeInsets.fromLTRB(24, 24, 24, 24), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _statusBento(), + const SizedBox(height: 32), + _frequencyChart(), + const SizedBox(height: 32), + _criticalEvents(), + const SizedBox(height: 32), + _eventLog(), + const SizedBox(height: 32), + _tacticalView(), + ], + ), + ); + } + + // ── Bento de estado ───────────────────────────────────────────────────────── + Widget _statusBento() => Column(children: [ + _activeMonitoringCard(), + const SizedBox(height: 16), + Row(children: [ + Expanded(child: _miniStatCard( + 'ALARMAS ACTIVAS', '03', Icons.warning, AppColors.error)), + const SizedBox(width: 16), + Expanded(child: _miniStatCard( + 'RESUELTAS 24H', '142', Icons.check_circle, AppColors.primary)), + ]), + ]); + + Widget _activeMonitoringCard() => Container( + width: double.infinity, + constraints: const BoxConstraints(minHeight: 160), + padding: const EdgeInsets.all(20), + decoration: BoxDecoration( + color: AppColors.surfaceHigh, + borderRadius: BorderRadius.circular(12)), + child: Stack( + clipBehavior: Clip.hardEdge, + children: [ + Positioned( + right: -20, bottom: -20, + child: Opacity(opacity: 0.1, + child: const Icon(Icons.shield, size: 120, color: AppColors.onSurface)), + ), + Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Row(children: [ + AnimatedBuilder( + animation: _pulseCtrl, + builder: (_, __) => Transform.scale( + scale: _pulseScale.value, + child: Container( + width: 8, height: 8, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: AppColors.primary, + boxShadow: [BoxShadow( + color: AppColors.primary.withOpacity(_pulseGlow.value), + blurRadius: 10, spreadRadius: 3)], + ), + ), + ), + ), + const SizedBox(width: 8), + Text('ESTADO DEL SISTEMA', + style: appLabel(size: 10, weight: FontWeight.bold, + color: AppColors.primary, spacing: 2.0)), + ]), + const SizedBox(height: 6), + Text('MONITOREO ACTIVO', + style: appHeadline(size: 28, weight: FontWeight.w800)), + const SizedBox(height: 8), + Text('Todos los sectores asegurados. 24 nodos en línea.', + style: appLabel(size: 12)), + ]), + ], + ), + ); + + Widget _miniStatCard(String label, String value, IconData icon, Color color) => + Container( + padding: const EdgeInsets.all(16), + decoration: BoxDecoration(color: AppColors.surfaceLow, + borderRadius: BorderRadius.circular(12)), + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Text(label, style: appLabel(size: 10, spacing: 2.0)), + const SizedBox(height: 16), + Row(crossAxisAlignment: CrossAxisAlignment.end, children: [ + Text(value, style: appHeadline(size: 36, color: color)), + const SizedBox(width: 6), + Padding(padding: const EdgeInsets.only(bottom: 4), + child: Icon(icon, color: color, size: 20)), + ]), + ]), + ); + + // ── Gráfico de frecuencia ─────────────────────────────────────────────────── + Widget _frequencyChart() { + const maxH = 110.0; + final fracciones = [0.40, 0.65, 0.95, 0.55, 0.30, 0.45, 0.20]; + final dias = ['LUN', 'MAR', 'MIÉ', 'JUE', 'VIE', 'SÁB', 'DOM']; + const picoIdx = 2; + + return Container( + padding: const EdgeInsets.all(24), + decoration: BoxDecoration(color: AppColors.surfaceLow, + borderRadius: BorderRadius.circular(12)), + child: Column(children: [ + Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Text('FRECUENCIA DE ALARMAS', + style: appHeadline(size: 13, spacing: 1.5)), + Container( + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 4), + decoration: BoxDecoration(color: AppColors.secondaryContainer, + borderRadius: BorderRadius.circular(99)), + child: Text('TENDENCIA SEMANAL', + style: appLabel(size: 10, weight: FontWeight.bold, + color: AppColors.onSecondaryContainer)), + ), + ]), + const SizedBox(height: 24), + SizedBox( + height: maxH + 20, + child: Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: List.generate(fracciones.length, (i) { + final isPico = i == picoIdx; + return Expanded( + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 3), + child: Column( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + if (isPico) + Padding( + padding: const EdgeInsets.only(bottom: 4), + child: Text('PICO', style: appLabel( + size: 9, weight: FontWeight.bold, + color: AppColors.error)), + ), + Container( + height: maxH * fracciones[i], + decoration: BoxDecoration( + color: isPico + ? AppColors.error.withOpacity(0.4) + : AppColors.primary.withOpacity(0.2), + borderRadius: const BorderRadius.vertical( + top: Radius.circular(4)), + ), + ), + ], + ), + ), + ); + }), + ), + ), + const SizedBox(height: 16), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: List.generate(dias.length, (i) => Text(dias[i], + style: appLabel(size: 10, + weight: i == picoIdx ? FontWeight.bold : FontWeight.normal, + color: i == picoIdx ? AppColors.onSurface : AppColors.onSurfaceVariant))), + ), + ]), + ); + } + + // ── Eventos críticos ──────────────────────────────────────────────────────── + Widget _criticalEvents() => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row(children: [ + const Icon(Icons.priority_high, color: AppColors.error, size: 16), + const SizedBox(width: 8), + Text('EVENTOS CRÍTICOS', + style: appHeadline(size: 13, color: AppColors.error, spacing: 1.5)), + ]), + const SizedBox(height: 16), + ClipRRect( + borderRadius: BorderRadius.circular(12), + child: IntrinsicHeight( + child: Row(crossAxisAlignment: CrossAxisAlignment.stretch, children: [ + Container(width: 6, color: AppColors.error), + Expanded( + child: Container( + color: AppColors.surfaceHigh, + padding: const EdgeInsets.fromLTRB(14, 20, 20, 20), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded(child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('INTRUSIÓN NIVEL 5', + style: appLabel(size: 10, weight: FontWeight.bold, + color: AppColors.error, spacing: 1.5)), + const SizedBox(height: 4), + Text('ALMACÉN PRINCIPAL G-4', + style: appHeadline(size: 18)), + const SizedBox(height: 8), + Row(children: [ + const Icon(Icons.schedule, size: 14, + color: AppColors.onSurfaceVariant), + const SizedBox(width: 6), + Text('02:14:45', style: appLabel(size: 12)), + ]), + ], + )), + const SizedBox(width: 12), + ElevatedButton( + onPressed: () {}, + style: ElevatedButton.styleFrom( + primary: AppColors.error, + onPrimary: AppColors.onError, + padding: const EdgeInsets.symmetric( + horizontal: 16, vertical: 10), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(8)), + elevation: 0, + ), + child: Text('RESPONDER', + style: appLabel(size: 12, weight: FontWeight.bold, + color: AppColors.onError)), + ), + ], + ), + ), + ), + ]), + ), + ), + ], + ); + + // ── Registro de eventos ───────────────────────────────────────────────────── + Widget _eventLog() => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row(mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ + Text('REGISTRO DE EVENTOS', + style: appHeadline(size: 13, spacing: 1.5)), + Text('Ver Historial', + style: appLabel(size: 12, weight: FontWeight.bold, + color: AppColors.primary)), + ]), + const SizedBox(height: 24), + _logEntry(icon: Icons.lock_open, iconBg: AppColors.surfaceHighest, + iconColor: AppColors.secondary, + title: 'Acceso Autorizado', badge: 'SEGURO', + badgeTextColor: AppColors.onSurfaceVariant, badgeBg: AppColors.surfaceLow, + description: 'Entrada: Muelle Trasero - Usuario: #0824', + time: '10:45:12', showLine: true), + _logEntry(icon: Icons.local_fire_department, + iconBg: AppColors.tertiaryContainer, iconColor: AppColors.tertiary, + title: 'Humo Detectado', badge: 'URGENTE', + badgeTextColor: AppColors.tertiary, badgeBg: AppColors.tertiaryContainer, + description: 'Sensor #402 - Sala de Servidores A', + time: '09:12:05', showLine: true), + _logEntry(icon: Icons.videocam, iconBg: AppColors.surfaceHighest, + iconColor: AppColors.primary, + title: 'Detección de Movimiento', badge: 'RESUELTO', + badgeTextColor: AppColors.onSurfaceVariant, badgeBg: AppColors.surfaceLow, + description: 'Cámara 12 - Cerca Perimetral Sur', + time: '08:55:30', showLine: false), + ], + ); + + Widget _logEntry({ + required IconData icon, required Color iconBg, required Color iconColor, + required String title, required String badge, required Color badgeTextColor, + required Color badgeBg, required String description, required String time, + required bool showLine, + }) => + Row(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Column(children: [ + Container(width: 32, height: 32, + decoration: BoxDecoration(color: iconBg, shape: BoxShape.circle), + child: Icon(icon, size: 16, color: iconColor)), + if (showLine) + Container(width: 1, height: 64, margin: const EdgeInsets.only(top: 4), + color: AppColors.outlineVariant.withOpacity(0.3)), + ]), + const SizedBox(width: 16), + Expanded(child: Padding( + padding: const EdgeInsets.only(bottom: 8), + child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Row(children: [ + Text(title, style: appHeadline(size: 14)), + const SizedBox(width: 8), + Container( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2), + decoration: BoxDecoration(color: badgeBg, + borderRadius: BorderRadius.circular(4)), + child: Text(badge, style: appLabel(size: 10, + weight: FontWeight.bold, color: badgeTextColor)), + ), + ]), + const SizedBox(height: 4), + Text(description, style: appLabel(size: 12)), + const SizedBox(height: 4), + Text(time, style: appLabel(size: 10, color: AppColors.outline)), + ]), + )), + ]); + + // ── Vista táctica ─────────────────────────────────────────────────────────── + Widget _tacticalView() => ClipRRect( + borderRadius: BorderRadius.circular(12), + child: SizedBox( + height: 192, + child: Stack(children: [ + Container( + width: double.infinity, + decoration: const BoxDecoration( + gradient: RadialGradient(center: Alignment.center, radius: 1.2, + colors: [Color(0xFF0A1628), AppColors.surfaceLow]), + ), + ), + CustomPaint(size: const Size(double.infinity, 192), + painter: _GridPainter()), + Container( + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.bottomCenter, end: Alignment.topCenter, + colors: [AppColors.surfaceLow, AppColors.surfaceLow.withOpacity(0.0)], + stops: const [0.0, 0.7], + ), + ), + ), + Positioned(top: 16, left: 16, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + decoration: BoxDecoration( + color: AppColors.surfaceHighest.withOpacity(0.85), + borderRadius: BorderRadius.circular(4)), + child: Text('VISTA TÁCTICA', style: appLabel( + size: 10, weight: FontWeight.bold, + color: AppColors.primary, spacing: 2.0)), + ), + ), + Positioned(top: 80, left: 110, + child: AnimatedBuilder( + animation: _pingCtrl, + builder: (_, __) => SizedBox(width: 40, height: 40, + child: Stack(alignment: Alignment.center, children: [ + Transform.scale(scale: _pingScale.value, + child: Opacity(opacity: _pingOpacity.value, + child: Container(width: 32, height: 32, + decoration: BoxDecoration(shape: BoxShape.circle, + color: AppColors.error.withOpacity(0.3))))), + Container(width: 12, height: 12, + decoration: BoxDecoration(shape: BoxShape.circle, + color: AppColors.error, + border: Border.all( + color: Colors.white.withOpacity(0.2), width: 1.5))), + ]), + ), + ), + ), + ]), + ), + ); +} + +class _GridPainter extends CustomPainter { + @override + void paint(Canvas canvas, Size size) { + final p = Paint() + ..color = const Color(0xFF1A3A5C).withOpacity(0.5) + ..strokeWidth = 0.5; + for (double x = 0; x <= size.width; x += 22) { + canvas.drawLine(Offset(x, 0), Offset(x, size.height), p); + } + for (double y = 0; y <= size.height; y += 22) { + canvas.drawLine(Offset(0, y), Offset(size.width, y), p); + } + } + + @override + bool shouldRepaint(covariant CustomPainter o) => false; +}