fix: reemplazar audioplayers por pantalla de llamada visual

audioplayers requiere GStreamer en Linux y causa problemas en otras
plataformas — se eliminó la dependencia completamente.

LlamadaPage mantiene toda la UX:
- Animación de pulso mientras llama
- Auto-conexión a los 5s con cronómetro
- Controles (silenciar, altavoz, teclado) al conectar
- Botón colgar

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Pablinux
2026-04-16 03:04:13 -05:00
co-authored by Claude Sonnet 4.6
parent daa4aca077
commit 1d243fcf44
2 changed files with 29 additions and 60 deletions
+29 -56
View File
@@ -1,10 +1,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:audioplayers/audioplayers.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import '../theme.dart'; import '../theme.dart';
enum _EstadoLlamada { llamando, conectado, finalizado } enum _EstadoLlamada { llamando, conectado }
class LlamadaPage extends StatefulWidget { class LlamadaPage extends StatefulWidget {
const LlamadaPage({Key? key}) : super(key: key); const LlamadaPage({Key? key}) : super(key: key);
@@ -15,7 +14,6 @@ class LlamadaPage extends StatefulWidget {
class _LlamadaPageState extends State<LlamadaPage> class _LlamadaPageState extends State<LlamadaPage>
with TickerProviderStateMixin { with TickerProviderStateMixin {
final _player = AudioPlayer();
_EstadoLlamada _estado = _EstadoLlamada.llamando; _EstadoLlamada _estado = _EstadoLlamada.llamando;
Timer? _timerConexion; Timer? _timerConexion;
Timer? _timerDuracion; Timer? _timerDuracion;
@@ -29,7 +27,6 @@ class _LlamadaPageState extends State<LlamadaPage>
void initState() { void initState() {
super.initState(); super.initState();
// ── Animación de pulso (llamando) ──────────────────────────────────────
_ringCtrl = AnimationController( _ringCtrl = AnimationController(
vsync: this, vsync: this,
duration: const Duration(milliseconds: 1400), duration: const Duration(milliseconds: 1400),
@@ -39,42 +36,22 @@ class _LlamadaPageState extends State<LlamadaPage>
_ringOpacity = Tween(begin: 0.5, end: 0.0) _ringOpacity = Tween(begin: 0.5, end: 0.0)
.animate(CurvedAnimation(parent: _ringCtrl, curve: Curves.easeOut)); .animate(CurvedAnimation(parent: _ringCtrl, curve: Curves.easeOut));
_iniciarTono();
// Simula que la central contesta tras 5 segundos // Simula que la central contesta tras 5 segundos
_timerConexion = Timer(const Duration(seconds: 5), _conectar); _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() { void _conectar() {
if (!mounted) return; if (!mounted) return;
setState(() => _estado = _EstadoLlamada.conectado); setState(() => _estado = _EstadoLlamada.conectado);
_player.stop();
_ringCtrl.stop(); _ringCtrl.stop();
// Inicia contador de duración
_timerDuracion = Timer.periodic(const Duration(seconds: 1), (_) { _timerDuracion = Timer.periodic(const Duration(seconds: 1), (_) {
if (mounted) setState(() => _segundos++); if (mounted) setState(() => _segundos++);
}); });
} }
Future<void> _colgar() async { void _colgar() {
_timerConexion?.cancel(); _timerConexion?.cancel();
_timerDuracion?.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); if (mounted) Navigator.pop(context);
} }
@@ -82,7 +59,6 @@ class _LlamadaPageState extends State<LlamadaPage>
void dispose() { void dispose() {
_timerConexion?.cancel(); _timerConexion?.cancel();
_timerDuracion?.cancel(); _timerDuracion?.cancel();
_player.dispose();
_ringCtrl.dispose(); _ringCtrl.dispose();
super.dispose(); super.dispose();
} }
@@ -101,9 +77,11 @@ class _LlamadaPageState extends State<LlamadaPage>
child: Column( child: Column(
children: [ children: [
const SizedBox(height: 48), const SizedBox(height: 48),
// ── Badge proveedor ────────────────────────────────────────── // ── Badge proveedor ──────────────────────────────────────────
Container( Container(
padding: const EdgeInsets.symmetric(horizontal: 14, vertical: 6), padding:
const EdgeInsets.symmetric(horizontal: 14, vertical: 6),
decoration: BoxDecoration( decoration: BoxDecoration(
color: AppColors.primary.withOpacity(0.12), color: AppColors.primary.withOpacity(0.12),
borderRadius: BorderRadius.circular(99), borderRadius: BorderRadius.circular(99),
@@ -127,7 +105,6 @@ class _LlamadaPageState extends State<LlamadaPage>
width: 160, width: 160,
height: 160, height: 160,
child: Stack(alignment: Alignment.center, children: [ child: Stack(alignment: Alignment.center, children: [
// Anillos de pulso (solo mientras llama)
if (_estado == _EstadoLlamada.llamando) if (_estado == _EstadoLlamada.llamando)
AnimatedBuilder( AnimatedBuilder(
animation: _ringCtrl, animation: _ringCtrl,
@@ -146,7 +123,6 @@ class _LlamadaPageState extends State<LlamadaPage>
), ),
), ),
), ),
// Avatar
Container( Container(
width: 110, width: 110,
height: 110, height: 110,
@@ -180,13 +156,11 @@ class _LlamadaPageState extends State<LlamadaPage>
color: Colors.white)), color: Colors.white)),
const SizedBox(height: 8), const SizedBox(height: 8),
// ── Estado ─────────────────────────────────────────────────── // ── Estado / cronómetro ──────────────────────────────────────
Text( Text(
_estado == _EstadoLlamada.llamando _estado == _EstadoLlamada.llamando
? 'Llamando...' ? 'Llamando...'
: _estado == _EstadoLlamada.conectado : _duracion,
? _duracion
: 'Llamada finalizada',
style: GoogleFonts.inter( style: GoogleFonts.inter(
fontSize: 15, fontSize: 15,
color: _estado == _EstadoLlamada.conectado color: _estado == _EstadoLlamada.conectado
@@ -196,9 +170,21 @@ class _LlamadaPageState extends State<LlamadaPage>
const Spacer(), const Spacer(),
// ── Botones de control ─────────────────────────────────────── // ── Controles (solo conectado) ───────────────────────────────
if (_estado == _EstadoLlamada.conectado) _controlesConectado(), if (_estado == _EstadoLlamada.conectado) ...[
const SizedBox(height: 32), 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 ───────────────────────────────────────────── // ── Botón colgar ─────────────────────────────────────────────
GestureDetector( GestureDetector(
@@ -207,13 +193,12 @@ class _LlamadaPageState extends State<LlamadaPage>
width: 72, width: 72,
height: 72, height: 72,
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: AppColors.error, color: AppColors.error, shape: BoxShape.circle),
shape: BoxShape.circle,
),
child: const Icon(Icons.call_end_rounded, child: const Icon(Icons.call_end_rounded,
color: Colors.white, size: 32), color: Colors.white, size: 32),
), ),
), ),
const SizedBox(height: 8),
Text('Colgar', Text('Colgar',
style: appLabel( style: appLabel(
size: 12, color: AppColors.onSurfaceVariant)), size: 12, color: AppColors.onSurfaceVariant)),
@@ -224,32 +209,20 @@ class _LlamadaPageState extends State<LlamadaPage>
); );
} }
Widget _controlesConectado() => Padding( Widget _controlBtn(IconData icon, String label) => Column(
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, mainAxisSize: MainAxisSize.min,
children: [ children: [
Container( Container(
width: 56, width: 56,
height: 56, height: 56,
decoration: decoration: BoxDecoration(
BoxDecoration(color: bg, shape: BoxShape.circle), color: AppColors.surfaceHigh, shape: BoxShape.circle),
child: Icon(icon, color: AppColors.onSurface, size: 24), child: Icon(icon, color: AppColors.onSurface, size: 24),
), ),
const SizedBox(height: 6), const SizedBox(height: 6),
Text(label, Text(label,
style: style: appLabel(
appLabel(size: 11, color: AppColors.onSurfaceVariant)), size: 11, color: AppColors.onSurfaceVariant)),
], ],
); );
} }
-4
View File
@@ -38,7 +38,6 @@ dependencies:
crypto: ^3.0.2 crypto: ^3.0.2
shared_preferences: ^2.0.0 shared_preferences: ^2.0.0
http: ^0.13.4 http: ^0.13.4
audioplayers: ^1.1.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
@@ -72,9 +71,6 @@ flutter:
assets: assets:
- lib/recursos/logo_app.png - lib/recursos/logo_app.png
- lib/recursos/tono_espera_llamada.wav
- lib/recursos/tono_llamda_espera.mp3
- lib/recursos/tono_notificacion.mp3
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware. # https://flutter.dev/assets-and-images/#resolution-aware.