import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; import '../estado/estado_radio.dart'; import '../servicios/servicio_audio.dart'; /// Barra inferior persistente con controles básicos de reproducción. /// Se muestra siempre que haya una emisora cargada. class MiniReproductor extends StatelessWidget { const MiniReproductor({super.key}); @override Widget build(BuildContext context) { final estado = context.watch(); final emisora = estado.emisoraActual; if (emisora == null) return const SizedBox.shrink(); final theme = Theme.of(context); return 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: [ // Logo emisora ClipRRect( borderRadius: BorderRadius.circular(6), child: Container( width: 40, height: 40, color: theme.colorScheme.primaryContainer, child: const Icon(Icons.radio, size: 22), ), ), 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( 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( 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), ), ); } return IconButton( icon: Icon(s == EstadoReproduccion.reproduciendo ? Icons.pause_rounded : Icons.play_arrow_rounded), onPressed: estado.togglePlay, tooltip: s == EstadoReproduccion.reproduciendo ? 'Pausar' : 'Reproducir', ); }, ), ], ), ), ), ); } String _labelEstado(EstadoReproduccion estado) { switch (estado) { case EstadoReproduccion.cargando: return 'Conectando...'; case EstadoReproduccion.reproduciendo: return 'En directo ●'; case EstadoReproduccion.pausado: return 'Pausado'; case EstadoReproduccion.error: return 'Error de conexión'; case EstadoReproduccion.detenido: return 'Detenido'; } } }