Some checks failed
Flutter CI/CD — PluriWave / Test + Build (push) Has been cancelled
Reviewed-on: #7
137 lines
5.0 KiB
Dart
137 lines
5.0 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
import '../estado/estado_radio.dart';
|
|
import '../pantallas/pantalla_reproductor.dart';
|
|
import '../servicios/servicio_audio.dart';
|
|
import 'visualizador_audio.dart';
|
|
|
|
/// Barra inferior persistente con controles básicos de reproducción.
|
|
/// Toca la barra para abrir PantallaReproductor completa.
|
|
class MiniReproductor extends StatelessWidget {
|
|
const MiniReproductor({super.key});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final estado = context.watch<EstadoRadio>();
|
|
final emisora = estado.emisoraActual;
|
|
|
|
if (emisora == null) return const SizedBox.shrink();
|
|
|
|
final theme = Theme.of(context);
|
|
|
|
return GestureDetector(
|
|
onTap: () => PantallaReproductor.abrir(context, emisora),
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: theme.colorScheme.surfaceContainer,
|
|
border: Border(
|
|
top: BorderSide(
|
|
color: theme.colorScheme.outlineVariant, width: 0.5)),
|
|
),
|
|
child: SafeArea(
|
|
top: false,
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
|
child: Row(
|
|
children: [
|
|
// Indicador de reproducción (mini visualizador)
|
|
SizedBox(
|
|
width: 40,
|
|
height: 40,
|
|
child: Center(
|
|
child: IndicadorReproduccion(
|
|
estadoStream: estado.estadoStream,
|
|
color: theme.colorScheme.primary,
|
|
size: 20,
|
|
),
|
|
),
|
|
),
|
|
const SizedBox(width: 12),
|
|
// Nombre y estado
|
|
Expanded(
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Text(
|
|
emisora.nombre,
|
|
style: theme.textTheme.bodyMedium
|
|
?.copyWith(fontWeight: FontWeight.w600),
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
),
|
|
StreamBuilder<EstadoReproduccion>(
|
|
stream: estado.estadoStream,
|
|
builder: (context, snapshot) {
|
|
final s = snapshot.data ??
|
|
EstadoReproduccion.detenido;
|
|
return Text(
|
|
_labelEstado(s),
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
// Botón play/pause
|
|
StreamBuilder<EstadoReproduccion>(
|
|
stream: estado.estadoStream,
|
|
builder: (context, snapshot) {
|
|
final s =
|
|
snapshot.data ?? EstadoReproduccion.detenido;
|
|
if (s == EstadoReproduccion.cargando) {
|
|
return const SizedBox(
|
|
width: 40,
|
|
height: 40,
|
|
child: Padding(
|
|
padding: EdgeInsets.all(10),
|
|
child: CircularProgressIndicator(strokeWidth: 2),
|
|
),
|
|
);
|
|
}
|
|
// En estado error: mostrar icono de reintento
|
|
if (s == EstadoReproduccion.error) {
|
|
final emisora = estado.emisoraActual;
|
|
return IconButton(
|
|
icon: const Icon(Icons.refresh_rounded),
|
|
tooltip: 'Reintentar',
|
|
onPressed: emisora != null
|
|
? () => estado.reproducir(emisora)
|
|
: null,
|
|
);
|
|
}
|
|
return IconButton(
|
|
icon: Icon(
|
|
s == EstadoReproduccion.reproduciendo
|
|
? Icons.pause_rounded
|
|
: Icons.play_arrow_rounded,
|
|
),
|
|
onPressed: () {
|
|
// Evitar que el tap en el botón abra el reproductor
|
|
estado.togglePlay();
|
|
},
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
String _labelEstado(EstadoReproduccion estado) {
|
|
return switch (estado) {
|
|
EstadoReproduccion.cargando => 'Conectando...',
|
|
EstadoReproduccion.reproduciendo => 'En directo ●',
|
|
EstadoReproduccion.pausado => 'Pausado',
|
|
EstadoReproduccion.error => 'Error de conexión',
|
|
EstadoReproduccion.detenido => 'Detenido',
|
|
};
|
|
}
|
|
}
|