feat: pantalla de llamada simulada con tono de espera
- LlamadaPage: pantalla fullscreen estilo llamada telefónica · Estado 'llamando' con animación de pulso y tono de espera en loop · Auto-conexión a los 5 segundos (simula que la central contesta) · Estado 'conectado' con cronómetro y controles (silenciar, altavoz, teclado) · Botón colgar detiene audio y cierra la pantalla - MensajeriaPage: botón llamar abre LlamadaPage directamente - pubspec.yaml: audioplayers ^1.1.0, assets de audio registrados Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
1a832330f2
commit
daa4aca077
@@ -0,0 +1,255 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:audioplayers/audioplayers.dart';
|
||||
import 'package:google_fonts/google_fonts.dart';
|
||||
import '../theme.dart';
|
||||
|
||||
enum _EstadoLlamada { llamando, conectado, finalizado }
|
||||
|
||||
class LlamadaPage extends StatefulWidget {
|
||||
const LlamadaPage({Key? key}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<LlamadaPage> createState() => _LlamadaPageState();
|
||||
}
|
||||
|
||||
class _LlamadaPageState extends State<LlamadaPage>
|
||||
with TickerProviderStateMixin {
|
||||
final _player = AudioPlayer();
|
||||
_EstadoLlamada _estado = _EstadoLlamada.llamando;
|
||||
Timer? _timerConexion;
|
||||
Timer? _timerDuracion;
|
||||
int _segundos = 0;
|
||||
|
||||
late final AnimationController _ringCtrl;
|
||||
late final Animation<double> _ringScale;
|
||||
late final Animation<double> _ringOpacity;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
// ── Animación de pulso (llamando) ──────────────────────────────────────
|
||||
_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));
|
||||
|
||||
_iniciarTono();
|
||||
|
||||
// Simula que la central contesta tras 5 segundos
|
||||
_timerConexion = Timer(const Duration(seconds: 5), _conectar);
|
||||
}
|
||||
|
||||
Future<void> _iniciarTono() async {
|
||||
try {
|
||||
await _player.setReleaseMode(ReleaseMode.loop);
|
||||
await _player.play(AssetSource('recursos/tono_espera_llamada.wav'));
|
||||
} catch (_) {
|
||||
// Si el wav falla intentar mp3
|
||||
try {
|
||||
await _player.play(AssetSource('recursos/tono_llamda_espera.mp3'));
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
void _conectar() {
|
||||
if (!mounted) return;
|
||||
setState(() => _estado = _EstadoLlamada.conectado);
|
||||
_player.stop();
|
||||
_ringCtrl.stop();
|
||||
// Inicia contador de duración
|
||||
_timerDuracion = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||
if (mounted) setState(() => _segundos++);
|
||||
});
|
||||
}
|
||||
|
||||
Future<void> _colgar() async {
|
||||
_timerConexion?.cancel();
|
||||
_timerDuracion?.cancel();
|
||||
await _player.stop();
|
||||
if (!mounted) return;
|
||||
setState(() => _estado = _EstadoLlamada.finalizado);
|
||||
await Future.delayed(const Duration(milliseconds: 600));
|
||||
if (mounted) Navigator.pop(context);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_timerConexion?.cancel();
|
||||
_timerDuracion?.cancel();
|
||||
_player.dispose();
|
||||
_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: [
|
||||
// Anillos de pulso (solo mientras llama)
|
||||
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),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
// Avatar
|
||||
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 ───────────────────────────────────────────────────
|
||||
Text(
|
||||
_estado == _EstadoLlamada.llamando
|
||||
? 'Llamando...'
|
||||
: _estado == _EstadoLlamada.conectado
|
||||
? _duracion
|
||||
: 'Llamada finalizada',
|
||||
style: GoogleFonts.inter(
|
||||
fontSize: 15,
|
||||
color: _estado == _EstadoLlamada.conectado
|
||||
? AppColors.primary
|
||||
: AppColors.onSurfaceVariant),
|
||||
),
|
||||
|
||||
const Spacer(),
|
||||
|
||||
// ── Botones de control ───────────────────────────────────────
|
||||
if (_estado == _EstadoLlamada.conectado) _controlesConectado(),
|
||||
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),
|
||||
),
|
||||
),
|
||||
Text('Colgar',
|
||||
style: appLabel(
|
||||
size: 12, color: AppColors.onSurfaceVariant)),
|
||||
const SizedBox(height: 56),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _controlesConectado() => Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 48),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||
children: [
|
||||
_controlBtn(Icons.mic_off, 'Silenciar', AppColors.surfaceHigh),
|
||||
_controlBtn(Icons.volume_up, 'Altavoz', AppColors.surfaceHigh),
|
||||
_controlBtn(Icons.dialpad, 'Teclado', AppColors.surfaceHigh),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
Widget _controlBtn(IconData icon, String label, Color bg) => Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Container(
|
||||
width: 56,
|
||||
height: 56,
|
||||
decoration:
|
||||
BoxDecoration(color: bg, shape: BoxShape.circle),
|
||||
child: Icon(icon, color: AppColors.onSurface, size: 24),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Text(label,
|
||||
style:
|
||||
appLabel(size: 11, color: AppColors.onSurfaceVariant)),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import '../theme.dart';
|
||||
import '../db/dao/mensajes_dao.dart';
|
||||
import '../models/mensaje.dart';
|
||||
import 'llamada_page.dart';
|
||||
|
||||
// ─── Página ───────────────────────────────────────────────────────────────────
|
||||
class MensajeriaPage extends StatefulWidget {
|
||||
@@ -66,74 +67,11 @@ class _MensajeriaPageState extends State<MensajeriaPage> {
|
||||
}
|
||||
|
||||
void _llamarCentral() {
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => AlertDialog(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||
title: Row(children: [
|
||||
Container(
|
||||
width: 40,
|
||||
height: 40,
|
||||
decoration: BoxDecoration(
|
||||
color: AppColors.primaryContainer,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: const Icon(Icons.call, color: AppColors.primary, size: 20),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||
Text('Llamar a Central',
|
||||
style: appHeadline(size: 15, weight: FontWeight.bold)),
|
||||
Text('Central de Monitoreo',
|
||||
style: appLabel(size: 12)),
|
||||
]),
|
||||
),
|
||||
]),
|
||||
content: Text(
|
||||
'¿Deseas iniciar una llamada de voz con la central de monitoreo?',
|
||||
style: appLabel(size: 13, color: AppColors.onSurfaceVariant),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: Text('Cancelar',
|
||||
style: appLabel(
|
||||
size: 13, color: AppColors.onSurfaceVariant)),
|
||||
),
|
||||
ElevatedButton.icon(
|
||||
onPressed: () {
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
backgroundColor: AppColors.surfaceHigh,
|
||||
content: Row(children: [
|
||||
const Icon(Icons.call, color: AppColors.primary, size: 18),
|
||||
const SizedBox(width: 10),
|
||||
Text('Conectando con Central de Monitoreo...',
|
||||
style: appLabel(
|
||||
size: 13, color: AppColors.onSurface)),
|
||||
]),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
},
|
||||
icon: const Icon(Icons.call, size: 16),
|
||||
label: Text('Llamar',
|
||||
style: appLabel(
|
||||
size: 13,
|
||||
weight: FontWeight.bold,
|
||||
color: AppColors.primaryContainer)),
|
||||
style: ElevatedButton.styleFrom(
|
||||
primary: AppColors.primary,
|
||||
onPrimary: AppColors.primaryContainer,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(8)),
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
],
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
fullscreenDialog: true,
|
||||
builder: (_) => const LlamadaPage(),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user