diff --git a/lib/pages/inicio_page.dart b/lib/pages/inicio_page.dart new file mode 100644 index 0000000..d931407 --- /dev/null +++ b/lib/pages/inicio_page.dart @@ -0,0 +1,756 @@ +import 'dart:async'; +import 'package:flutter/material.dart'; +import '../theme.dart'; +import 'mensageria_page.dart'; + +// ─── Datos del banner ───────────────────────────────────────────────────────── +class _BannerData { + final String badge; + final String title; + final String subtitle; + final List gradientColors; + const _BannerData({ + required this.badge, + required this.title, + required this.subtitle, + required this.gradientColors, + }); +} + +const _banners = [ + _BannerData( + badge: 'Premium Access', + title: 'Vigilancia 24/7 Redes AI', + subtitle: 'Monitoreo inteligente con detección de patrones avanzada.', + gradientColors: [Color(0xFF001640), Color(0xFF0A1628)], + ), + _BannerData( + badge: 'Nuevo Servicio', + title: 'Control de Acceso Biométrico', + subtitle: 'Identificación facial y dactilar en tiempo real.', + gradientColors: [Color(0xFF1A0028), Color(0xFF0A0E14)], + ), + _BannerData( + badge: 'Actualización', + title: 'Sensores de Última Generación', + subtitle: 'Mayor cobertura con menor consumo energético.', + gradientColors: [Color(0xFF001A14), Color(0xFF0A0E14)], + ), +]; + +// ─── Datos del log de eventos ───────────────────────────────────────────────── +class _EventData { + final IconData icon; + final Color iconColor; + final Color iconBg; + final String tipo; + final Color tipoColor; + final String titulo; + final String descripcion; + final String hora; + const _EventData({ + required this.icon, + required this.iconColor, + required this.iconBg, + required this.tipo, + required this.tipoColor, + required this.titulo, + required this.descripcion, + required this.hora, + }); +} + +const _eventos = [ + _EventData( + icon: Icons.home_work_outlined, + iconColor: AppColors.error, + iconBg: Color(0xFF93000A), + tipo: 'Alerta Crítica', + tipoColor: AppColors.error, + titulo: 'Apertura No Autorizada', + descripcion: 'Zona A-3: Sensor de puerta perimetral activado.', + hora: '10:45 AM', + ), + _EventData( + icon: Icons.campaign_outlined, + iconColor: AppColors.onSecondaryContainer, + iconBg: AppColors.secondaryContainer, + tipo: 'Noticia', + tipoColor: AppColors.onSecondaryContainer, + titulo: 'Mantenimiento Programado', + descripcion: + 'Actualización de firmware para sensores de movimiento el 24/05.', + hora: '09:12 AM', + ), + _EventData( + icon: Icons.notifications_active_outlined, + iconColor: AppColors.primary, + iconBg: AppColors.primaryContainer, + tipo: 'Notificación', + tipoColor: AppColors.primary, + titulo: 'Sistema Armado', + descripcion: 'Activación exitosa por usuario Juan Pérez.', + hora: '08:00 AM', + ), + _EventData( + icon: Icons.history, + iconColor: AppColors.outline, + iconBg: AppColors.surfaceHighest, + tipo: 'Evento General', + tipoColor: AppColors.outline, + titulo: 'Cierre Periódico', + descripcion: 'Revisión de integridad del sistema completada sin errores.', + hora: 'AYER', + ), +]; + +// ─── Página ─────────────────────────────────────────────────────────────────── +class InicioPage extends StatefulWidget { + const InicioPage({Key? key}) : super(key: key); + + @override + State createState() => _InicioPageState(); +} + +class _InicioPageState extends State + with SingleTickerProviderStateMixin { + int _bannerPage = 0; + final _pageController = PageController(); + Timer? _bannerTimer; + + late final AnimationController _panicCtrl; + late final Animation _pingScale; + late final Animation _pingOpacity; + + @override + void initState() { + super.initState(); + // Auto-avance del banner cada 4 segundos + _bannerTimer = Timer.periodic(const Duration(seconds: 4), (_) { + final next = (_bannerPage + 1) % _banners.length; + _pageController.animateToPage( + next, + duration: const Duration(milliseconds: 450), + curve: Curves.easeInOut, + ); + }); + _panicCtrl = AnimationController( + vsync: this, duration: const Duration(milliseconds: 1000)) + ..repeat(); + _pingScale = Tween(begin: 1.0, end: 2.2) + .animate(CurvedAnimation(parent: _panicCtrl, curve: Curves.easeOut)); + _pingOpacity = Tween(begin: 0.5, end: 0.0) + .animate(CurvedAnimation(parent: _panicCtrl, curve: Curves.easeOut)); + } + + @override + void dispose() { + _bannerTimer?.cancel(); + _pageController.dispose(); + _panicCtrl.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Stack( + children: [ + SingleChildScrollView( + padding: const EdgeInsets.fromLTRB(20, 20, 20, 88), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _sponsorCard(), + const SizedBox(height: 28), + _bannerSlider(), + const SizedBox(height: 28), + _quickMetrics(), + const SizedBox(height: 28), + _eventLog(), + ], + ), + ), + // FAB + Positioned( + bottom: 16, + right: 0, + child: _fab(), + ), + ], + ); + } + + // ── Sponsor ──────────────────────────────────────────────────────────────── + Widget _sponsorCard() => Column( + children: [ + // ── Sección usuario (sin tarjeta) ───────────────────────────────── + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Text('Bienvenido', + style: + appLabel(size: 11, color: AppColors.onSurfaceVariant)), + const SizedBox(height: 2), + Text('Juan Díaz', + style: appHeadline( + size: 20, + weight: FontWeight.w800, + color: AppColors.onSurface)), + ]), + // Avatar + Stack(clipBehavior: Clip.none, children: [ + Container( + width: 52, + height: 52, + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(14), + gradient: const LinearGradient( + colors: [AppColors.primaryContainer, Color(0xFF001640)], + begin: Alignment.topLeft, + end: Alignment.bottomRight, + ), + border: Border.all( + color: AppColors.primary.withOpacity(0.3), width: 1), + ), + child: const Icon(Icons.person_rounded, + size: 28, color: AppColors.primary), + ), + Positioned( + bottom: 2, + right: 2, + child: Container( + width: 11, + height: 11, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: const Color(0xFF4CAF50), + border: + Border.all(color: AppColors.surfaceLowest, width: 2), + ), + ), + ), + ]), + ], + ), + + // ── Línea separadora ────────────────────────────────────────────── + Container( + margin: const EdgeInsets.symmetric(vertical: 16), + height: 1, + color: AppColors.outlineVariant.withOpacity(0.35), + ), + + // ── Tarjeta ALARM WORK (sin cambios) ────────────────────────────── + Container( + width: double.infinity, + padding: const EdgeInsets.all(24), + decoration: BoxDecoration( + color: AppColors.surfaceLow, + borderRadius: BorderRadius.circular(16), + ), + child: Column(children: [ + SizedBox( + width: 64, + height: 64, + child: CustomPaint(painter: _ShieldPainter()), + ), + const SizedBox(height: 12), + Row(mainAxisAlignment: MainAxisAlignment.center, children: [ + Text('ALARM WORK', + style: appHeadline( + size: 20, + weight: FontWeight.w800, + color: AppColors.onSurface, + spacing: -0.5)), + const SizedBox(width: 6), + const Icon(Icons.verified_rounded, + color: AppColors.outline, size: 18), + ]), + const SizedBox(height: 4), + Text('Partner de Seguridad', + style: appLabel( + size: 10, + weight: FontWeight.bold, + color: AppColors.outline, + spacing: 2.5)), + ]), + ), + ], + ); + + // ── Banner slider ────────────────────────────────────────────────────────── + Widget _bannerSlider() => Column( + children: [ + // Cabecera + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('SERVICIOS Y PUBLICIDAD', + style: appLabel( + size: 10, + weight: FontWeight.bold, + color: AppColors.primary.withOpacity(0.8), + spacing: 2.0)), + // Dots tappables + Row( + children: List.generate(_banners.length, (i) { + final active = i == _bannerPage; + return GestureDetector( + onTap: () => _pageController.animateToPage( + i, + duration: const Duration(milliseconds: 350), + curve: Curves.easeInOut, + ), + child: AnimatedContainer( + duration: const Duration(milliseconds: 250), + margin: const EdgeInsets.only(left: 4), + width: active ? 16 : 8, + height: 4, + decoration: BoxDecoration( + color: + active ? AppColors.primary : AppColors.surfaceHighest, + borderRadius: BorderRadius.circular(99), + ), + ), + ); + })), + ], + ), + const SizedBox(height: 12), + // PageView con flechas de navegación + SizedBox( + height: 192, + child: Stack(children: [ + PageView.builder( + controller: _pageController, + itemCount: _banners.length, + onPageChanged: (i) => setState(() => _bannerPage = i), + itemBuilder: (_, i) => _bannerCard(_banners[i]), + ), + // Flecha izquierda + if (_bannerPage > 0) + Positioned( + left: 8, + top: 0, + bottom: 0, + child: Center( + child: _arrowButton(Icons.chevron_left, () { + _pageController.previousPage( + duration: const Duration(milliseconds: 350), + curve: Curves.easeInOut, + ); + })), + ), + // Flecha derecha + if (_bannerPage < _banners.length - 1) + Positioned( + right: 8, + top: 0, + bottom: 0, + child: Center( + child: _arrowButton(Icons.chevron_right, () { + _pageController.nextPage( + duration: const Duration(milliseconds: 350), + curve: Curves.easeInOut, + ); + })), + ), + ]), + ), + ], + ); + + Widget _arrowButton(IconData icon, VoidCallback onTap) => GestureDetector( + onTap: onTap, + child: Container( + width: 32, + height: 32, + decoration: BoxDecoration( + color: AppColors.surfaceLowest.withOpacity(0.6), + shape: BoxShape.circle, + ), + child: Icon(icon, color: AppColors.onSurface, size: 20), + ), + ); + + Widget _bannerCard(_BannerData data) => ClipRRect( + borderRadius: BorderRadius.circular(16), + child: Stack(children: [ + // Fondo degradado + Container( + decoration: BoxDecoration( + gradient: LinearGradient( + colors: data.gradientColors, + begin: Alignment.topRight, + end: Alignment.bottomLeft, + ), + ), + ), + // Grid decorativo + CustomPaint( + size: const Size(double.infinity, 192), + painter: _BannerGridPainter(), + ), + // Figuras geométricas decorativas + Positioned( + right: -30, + top: -30, + child: Container( + width: 160, + height: 160, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + color: AppColors.primary.withOpacity(0.08), width: 1), + ), + ), + ), + Positioned( + right: 20, + top: 20, + child: Container( + width: 80, + height: 80, + decoration: BoxDecoration( + shape: BoxShape.circle, + border: Border.all( + color: AppColors.primary.withOpacity(0.12), width: 1), + ), + ), + ), + // Gradient overlay inferior + Container( + decoration: BoxDecoration( + gradient: LinearGradient( + begin: Alignment.bottomCenter, + end: Alignment.topCenter, + colors: [ + Colors.black.withOpacity(0.8), + Colors.transparent, + ], + stops: const [0.0, 0.6], + ), + ), + ), + // Contenido + Positioned( + bottom: 0, + left: 0, + right: 0, + child: Padding( + padding: const EdgeInsets.all(20), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + padding: + const EdgeInsets.symmetric(horizontal: 10, vertical: 4), + decoration: BoxDecoration( + color: AppColors.primary.withOpacity(0.2), + borderRadius: BorderRadius.circular(6), + ), + child: Text(data.badge, + style: appLabel( + size: 10, + weight: FontWeight.bold, + color: AppColors.primary, + spacing: 1.5)), + ), + const SizedBox(height: 8), + Text(data.title, + style: appHeadline( + size: 20, + weight: FontWeight.w800, + color: AppColors.onSurface)), + const SizedBox(height: 4), + Text(data.subtitle, + style: + appLabel(size: 12, color: AppColors.onSurfaceVariant), + maxLines: 2), + ], + ), + ), + ), + ]), + ); + + // ── Métricas rápidas ─────────────────────────────────────────────────────── + Widget _quickMetrics() => Row(children: [ + Expanded( + child: _metricCard( + icon: Icons.lock_rounded, + iconColor: AppColors.primary, + label: 'Estado Sistema', + value: 'PROTEGIDO', + valueColor: AppColors.primary, + )), + const SizedBox(width: 12), + Expanded( + child: _metricCard( + icon: Icons.sensors, + iconColor: AppColors.tertiary, + label: 'Nodos Activos', + value: '12', + valueSuffix: ' ONLINE', + valueColor: AppColors.onSurface, + suffixColor: AppColors.outline, + )), + ]); + + Widget _metricCard({ + required IconData icon, + required Color iconColor, + required String label, + required String value, + required Color valueColor, + String? valueSuffix, + Color? suffixColor, + }) => + Container( + height: 128, + padding: const EdgeInsets.all(16), + decoration: BoxDecoration( + color: AppColors.surfaceLow, + borderRadius: BorderRadius.circular(16), + ), + child: Stack(children: [ + // Ícono de fondo decorativo + Positioned( + right: -8, + top: -8, + child: Opacity( + opacity: 0.05, + child: Icon(Icons.shield, size: 72, color: AppColors.onSurface), + ), + ), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Icon(icon, color: iconColor, size: 24), + Column(crossAxisAlignment: CrossAxisAlignment.start, children: [ + Text(label, + style: appLabel( + size: 9, + weight: FontWeight.bold, + color: AppColors.outline, + spacing: 2.0)), + const SizedBox(height: 2), + RichText( + text: TextSpan( + text: value, + style: appHeadline( + size: 20, weight: FontWeight.w800, color: valueColor), + children: valueSuffix != null + ? [ + TextSpan( + text: valueSuffix, + style: appLabel( + size: 11, + color: suffixColor ?? AppColors.outline), + ) + ] + : null, + ), + ), + ]), + ], + ), + ]), + ); + + // ── Log de eventos ───────────────────────────────────────────────────────── + Widget _eventLog() => Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('LOG DE EVENTOS Y NOTIFICACIONES', + style: appLabel( + size: 10, + weight: FontWeight.bold, + color: AppColors.primary.withOpacity(0.8), + spacing: 1.5)), + const Icon(Icons.filter_list, color: AppColors.outline, size: 20), + ], + ), + const SizedBox(height: 20), + ...List.generate( + _eventos.length, + (i) => _eventItem( + data: _eventos[i], + showLine: i < _eventos.length - 1, + )), + ], + ); + + Widget _eventItem({required _EventData data, required bool showLine}) => + Row(crossAxisAlignment: CrossAxisAlignment.start, children: [ + // Ícono + línea vertical + Column(children: [ + Container( + width: 48, + height: 48, + decoration: BoxDecoration( + color: data.iconBg, + shape: BoxShape.circle, + ), + child: Icon(data.icon, color: data.iconColor, size: 22), + ), + if (showLine) + Container( + width: 2, + height: 56, + margin: const EdgeInsets.symmetric(vertical: 4), + color: AppColors.outlineVariant.withOpacity(0.3), + ), + ]), + const SizedBox(width: 16), + // Contenido + Expanded( + child: Padding( + padding: const EdgeInsets.only(top: 2, bottom: 8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text(data.tipo.toUpperCase(), + style: appLabel( + size: 10, + weight: FontWeight.bold, + color: data.tipoColor, + spacing: 1.5)), + Text(data.hora, + style: appLabel( + size: 10, + weight: FontWeight.w500, + color: AppColors.outline)), + ], + ), + const SizedBox(height: 4), + Text(data.titulo, style: appHeadline(size: 14)), + const SizedBox(height: 2), + Text(data.descripcion, + style: + appLabel(size: 12, color: AppColors.onSurfaceVariant)), + ], + ), + ), + ), + ]); + + // ── Botón de pánico ──────────────────────────────────────────────────────── + Widget _fab() => GestureDetector( + onTap: () => Navigator.push( + context, + MaterialPageRoute(builder: (_) => const MensajeriaPage()), + ), + child: SizedBox( + width: 72, + height: 72, + child: Stack(alignment: Alignment.center, children: [ + // Anillo de ping animado + AnimatedBuilder( + animation: _panicCtrl, + builder: (_, __) => Transform.scale( + scale: _pingScale.value, + child: Opacity( + opacity: _pingOpacity.value, + child: Container( + width: 56, + height: 56, + decoration: BoxDecoration( + shape: BoxShape.circle, + color: AppColors.error.withOpacity(0.35), + ), + ), + ), + ), + ), + // Botón + Container( + width: 56, + height: 56, + decoration: BoxDecoration( + color: Color.fromARGB(255, 185, 19, 1), + shape: BoxShape.circle, + boxShadow: [ + BoxShadow( + color: Color.fromARGB(255, 247, 26, 1).withOpacity(0.4), + blurRadius: 16, + spreadRadius: 2, + offset: const Offset(0, 4), + ), + ], + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.warning_rounded, + color: Colors.white, size: 22), + Text('PÁNICO', + style: appLabel( + size: 8, + weight: FontWeight.bold, + color: Color.fromARGB(255, 255, 255, 255), + spacing: 1.0)), + ], + ), + ), + ]), + ), + ); +} + +// ─── Painters ───────────────────────────────────────────────────────────────── +class _ShieldPainter extends CustomPainter { + @override + void paint(Canvas canvas, Size size) { + final paint = Paint() + ..color = AppColors.primary + ..style = PaintingStyle.fill; + final path = Path(); + final w = size.width; + final h = size.height; + path.moveTo(w * 0.5, 0); + path.lineTo(w * 0.1, h * 0.2); + path.lineTo(w * 0.1, h * 0.55); + path.quadraticBezierTo(w * 0.1, h * 0.9, w * 0.5, h); + path.quadraticBezierTo(w * 0.9, h * 0.9, w * 0.9, h * 0.55); + path.lineTo(w * 0.9, h * 0.2); + path.close(); + canvas.drawPath(path, paint); + + // Círculo interior + final innerPaint = Paint() + ..color = AppColors.primaryContainer.withOpacity(0.5) + ..style = PaintingStyle.fill; + canvas.drawCircle(Offset(w * 0.5, h * 0.52), w * 0.18, innerPaint); + } + + @override + bool shouldRepaint(covariant CustomPainter o) => false; +} + +class _BannerGridPainter extends CustomPainter { + @override + void paint(Canvas canvas, Size size) { + final p = Paint() + ..color = AppColors.primary.withOpacity(0.06) + ..strokeWidth = 0.5; + for (double x = 0; x <= size.width; x += 24) { + canvas.drawLine(Offset(x, 0), Offset(x, size.height), p); + } + for (double y = 0; y <= size.height; y += 24) { + canvas.drawLine(Offset(0, y), Offset(size.width, y), p); + } + } + + @override + bool shouldRepaint(covariant CustomPainter o) => false; +}