import 'dart:async'; import 'package:flutter/material.dart'; import 'package:google_fonts/google_fonts.dart'; import '../theme.dart'; enum _EstadoLlamada { llamando, conectado } class LlamadaPage extends StatefulWidget { const LlamadaPage({Key? key}) : super(key: key); @override State createState() => _LlamadaPageState(); } class _LlamadaPageState extends State with TickerProviderStateMixin { _EstadoLlamada _estado = _EstadoLlamada.llamando; Timer? _timerConexion; Timer? _timerDuracion; int _segundos = 0; late final AnimationController _ringCtrl; late final Animation _ringScale; late final Animation _ringOpacity; @override void initState() { super.initState(); _ringCtrl = AnimationController( vsync: this, duration: const Duration(milliseconds: 1400), )..repeat(); _ringScale = Tween(begin: 1.0, end: 2.2) .animate(CurvedAnimation(parent: _ringCtrl, curve: Curves.easeOut)); _ringOpacity = Tween(begin: 0.5, end: 0.0) .animate(CurvedAnimation(parent: _ringCtrl, curve: Curves.easeOut)); // Simula que la central contesta tras 5 segundos _timerConexion = Timer(const Duration(seconds: 5), _conectar); } void _conectar() { if (!mounted) return; setState(() => _estado = _EstadoLlamada.conectado); _ringCtrl.stop(); _timerDuracion = Timer.periodic(const Duration(seconds: 1), (_) { if (mounted) setState(() => _segundos++); }); } void _colgar() { _timerConexion?.cancel(); _timerDuracion?.cancel(); if (mounted) Navigator.pop(context); } @override void dispose() { _timerConexion?.cancel(); _timerDuracion?.cancel(); _ringCtrl.dispose(); super.dispose(); } String get _duracion { final m = (_segundos ~/ 60).toString().padLeft(2, '0'); final s = (_segundos % 60).toString().padLeft(2, '0'); return '$m:$s'; } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: const Color(0xFF050A0F), body: SafeArea( child: Column( children: [ const SizedBox(height: 48), // ── Badge proveedor ────────────────────────────────────────── Container( padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6), decoration: BoxDecoration( color: AppColors.primary.withOpacity(0.12), borderRadius: BorderRadius.circular(99), border: Border.all( color: AppColors.primary.withOpacity(0.3), width: 1), ), child: Row(mainAxisSize: MainAxisSize.min, children: [ const Icon(Icons.shield, size: 14, color: AppColors.primary), const SizedBox(width: 6), Text('Central de Monitoreo', style: appLabel( size: 12, weight: FontWeight.bold, color: AppColors.primary)), ]), ), const SizedBox(height: 32), // ── Avatar con pulso ───────────────────────────────────────── SizedBox( width: 160, height: 160, child: Stack(alignment: Alignment.center, children: [ if (_estado == _EstadoLlamada.llamando) AnimatedBuilder( animation: _ringCtrl, builder: (_, __) => Transform.scale( scale: _ringScale.value, child: Opacity( opacity: _ringOpacity.value, child: Container( width: 110, height: 110, decoration: BoxDecoration( shape: BoxShape.circle, color: AppColors.primary.withOpacity(0.4), ), ), ), ), ), Container( width: 110, height: 110, decoration: BoxDecoration( shape: BoxShape.circle, color: AppColors.surfaceHigh, border: Border.all( color: _estado == _EstadoLlamada.conectado ? AppColors.primary : AppColors.outlineVariant, width: 2, ), ), child: Icon( Icons.shield, size: 50, color: _estado == _EstadoLlamada.conectado ? AppColors.primary : AppColors.onSurfaceVariant, ), ), ]), ), const SizedBox(height: 28), // ── Nombre ─────────────────────────────────────────────────── Text('Central de Seguridad', style: GoogleFonts.manrope( fontSize: 22, fontWeight: FontWeight.w700, color: Colors.white)), const SizedBox(height: 8), // ── Estado / cronómetro ────────────────────────────────────── Text( _estado == _EstadoLlamada.llamando ? 'Llamando...' : _duracion, style: GoogleFonts.inter( fontSize: 15, color: _estado == _EstadoLlamada.conectado ? AppColors.primary : AppColors.onSurfaceVariant), ), const Spacer(), // ── Controles (solo conectado) ─────────────────────────────── if (_estado == _EstadoLlamada.conectado) ...[ Padding( padding: const EdgeInsets.symmetric(horizontal: 48), child: Row( mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ _controlBtn(Icons.mic_off, 'Silenciar'), _controlBtn(Icons.volume_up, 'Altavoz'), _controlBtn(Icons.dialpad, 'Teclado'), ], ), ), const SizedBox(height: 32), ], // ── Botón colgar ───────────────────────────────────────────── GestureDetector( onTap: _colgar, child: Container( width: 72, height: 72, decoration: const BoxDecoration( color: AppColors.error, shape: BoxShape.circle), child: const Icon(Icons.call_end_rounded, color: Colors.white, size: 32), ), ), const SizedBox(height: 8), Text('Colgar', style: appLabel( size: 12, color: AppColors.onSurfaceVariant)), const SizedBox(height: 56), ], ), ), ); } Widget _controlBtn(IconData icon, String label) => Column( mainAxisSize: MainAxisSize.min, children: [ Container( width: 56, height: 56, decoration: BoxDecoration( color: AppColors.surfaceHigh, shape: BoxShape.circle), child: Icon(icon, color: AppColors.onSurface, size: 24), ), const SizedBox(height: 6), Text(label, style: appLabel( size: 11, color: AppColors.onSurfaceVariant)), ], ); }