feat(v0.3.0): ecualizador + favoritos en tarjeta + emisoras custom + export/import + fix MainActivity
Some checks failed
Flutter CI/CD — PluriWave / Test + Build (push) Has been cancelled
Some checks failed
Flutter CI/CD — PluriWave / Test + Build (push) Has been cancelled
- MainActivity: extiende AudioServiceActivity (fix pantalla en blanco) - ServicioAudio: AndroidEqualizer en AudioPipeline, aplicarPreset(), setBanda() - PresetEcualizador: modelo independiente (Flat/Rock/Pop/BassBoost/Jazz/Voz) - EcualizadorWidget: 5 sliders verticales + PresetsEcualizadorWidget - TarjetaEmisora: botón favorito visible en grid y lista (toggle con SnackBar) - EstadoRadio: emisoras custom (CRUD), export/import JSON v1, presets por emisora - PantallaAjustes: ecualizador interactivo, form añadir emisora, backup export/import - pubspec: +file_picker ^8.1.7, +uuid ^4.5.1
This commit is contained in:
120
lib/widgets/ecualizador_widget.dart
Normal file
120
lib/widgets/ecualizador_widget.dart
Normal file
@@ -0,0 +1,120 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import '../modelos/preset_ecualizador.dart';
|
||||
|
||||
/// Widget de ecualizador con 5 sliders verticales.
|
||||
/// Basado en JaviHogar EcualizadorWidget, adaptado a Material You.
|
||||
class EcualizadorWidget extends StatefulWidget {
|
||||
final PresetEcualizador preset;
|
||||
final void Function(PresetEcualizador) onCambio;
|
||||
|
||||
const EcualizadorWidget({super.key, required this.preset, required this.onCambio});
|
||||
|
||||
@override
|
||||
State<EcualizadorWidget> createState() => _EcualizadorWidgetState();
|
||||
}
|
||||
|
||||
class _EcualizadorWidgetState extends State<EcualizadorWidget> {
|
||||
late List<double> _bandas;
|
||||
final List<String> _etiquetas = ['60Hz', '250Hz', '1kHz', '4kHz', '16kHz'];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_bandas = List.from(widget.preset.bandas);
|
||||
}
|
||||
|
||||
@override
|
||||
void didUpdateWidget(EcualizadorWidget old) {
|
||||
super.didUpdateWidget(old);
|
||||
if (old.preset.nombre != widget.preset.nombre) {
|
||||
setState(() => _bandas = List.from(widget.preset.bandas));
|
||||
}
|
||||
}
|
||||
|
||||
void _actualizarBanda(int index, double valor) {
|
||||
setState(() => _bandas[index] = valor);
|
||||
widget.onCambio(PresetEcualizador(nombre: 'Personalizado', bandas: List.from(_bandas)));
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Card(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text('Ecualizador', style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: [
|
||||
for (int i = 0; i < 5; i++)
|
||||
Expanded(
|
||||
child: Column(
|
||||
children: [
|
||||
SizedBox(
|
||||
height: 160,
|
||||
child: RotatedBox(
|
||||
quarterTurns: 3,
|
||||
child: Slider(
|
||||
value: _bandas[i],
|
||||
min: -12.0,
|
||||
max: 12.0,
|
||||
divisions: 24,
|
||||
onChanged: (v) => _actualizarBanda(i, v),
|
||||
),
|
||||
),
|
||||
),
|
||||
Text(
|
||||
'${_bandas[i].toStringAsFixed(1)}dB',
|
||||
style: theme.textTheme.labelSmall,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
Text(
|
||||
_etiquetas[i],
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/// Chips de presets predefinidos.
|
||||
class PresetsEcualizadorWidget extends StatelessWidget {
|
||||
final PresetEcualizador presetActual;
|
||||
final void Function(PresetEcualizador) onSeleccionar;
|
||||
|
||||
const PresetsEcualizadorWidget({
|
||||
super.key,
|
||||
required this.presetActual,
|
||||
required this.onSeleccionar,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 4,
|
||||
children: PresetEcualizador.presets.map((p) {
|
||||
return ChoiceChip(
|
||||
label: Text(p.nombre),
|
||||
selected: p.nombre == presetActual.nombre,
|
||||
onSelected: (_) => onSeleccionar(p),
|
||||
);
|
||||
}).toList(),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shimmer/shimmer.dart';
|
||||
import '../estado/estado_radio.dart';
|
||||
import '../modelos/emisora.dart';
|
||||
|
||||
/// Tarjeta compacta para mostrar una emisora en listas y grids.
|
||||
class TarjetaEmisora extends StatelessWidget {
|
||||
/// Incluye botón de favorito visible en ambos modos.
|
||||
class TarjetaEmisora extends StatefulWidget {
|
||||
final Emisora emisora;
|
||||
final VoidCallback? onTap;
|
||||
final bool esCompacta;
|
||||
@@ -16,48 +19,96 @@ class TarjetaEmisora extends StatelessWidget {
|
||||
this.esCompacta = false,
|
||||
});
|
||||
|
||||
@override
|
||||
State<TarjetaEmisora> createState() => _TarjetaEmisoraState();
|
||||
}
|
||||
|
||||
class _TarjetaEmisoraState extends State<TarjetaEmisora> {
|
||||
bool _esFavorito = false;
|
||||
bool _toggling = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_checkFavorito();
|
||||
}
|
||||
|
||||
Future<void> _checkFavorito() async {
|
||||
final fav = await context.read<EstadoRadio>().esFavorito(widget.emisora.uuid);
|
||||
if (mounted) setState(() => _esFavorito = fav);
|
||||
}
|
||||
|
||||
Future<void> _toggle() async {
|
||||
if (_toggling) return;
|
||||
_toggling = true;
|
||||
final estado = context.read<EstadoRadio>();
|
||||
final esFav = await estado.toggleFavorito(widget.emisora);
|
||||
if (mounted) setState(() => _esFavorito = esFav);
|
||||
_toggling = false;
|
||||
if (mounted) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
|
||||
content: Text(esFav
|
||||
? '${widget.emisora.nombre} añadida a favoritos'
|
||||
: '${widget.emisora.nombre} eliminada de favoritos'),
|
||||
duration: const Duration(seconds: 2),
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Card(
|
||||
clipBehavior: Clip.antiAlias,
|
||||
child: InkWell(
|
||||
onTap: onTap,
|
||||
child: esCompacta ? _buildCompacta(theme) : _buildCompleta(theme),
|
||||
onTap: widget.onTap,
|
||||
child: widget.esCompacta
|
||||
? _buildCompacta(theme)
|
||||
: _buildCompleta(theme),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildCompleta(ThemeData theme) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
return Stack(
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: _logo(theme, 60),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
emisora.nombre,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
if (emisora.pais != null)
|
||||
Text(
|
||||
emisora.pais!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
AspectRatio(
|
||||
aspectRatio: 1,
|
||||
child: _logo(theme, 60),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(8, 8, 8, 4),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
widget.emisora.nombre,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(fontWeight: FontWeight.bold),
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
if (widget.emisora.pais != null)
|
||||
Text(
|
||||
widget.emisora.pais!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
// Botón favorito superpuesto (esquina superior derecha)
|
||||
Positioned(
|
||||
top: 4,
|
||||
right: 4,
|
||||
child: _botonFavorito(theme, mini: true),
|
||||
),
|
||||
],
|
||||
);
|
||||
@@ -67,22 +118,46 @@ class TarjetaEmisora extends StatelessWidget {
|
||||
return ListTile(
|
||||
leading: SizedBox(width: 48, height: 48, child: _logo(theme, 24)),
|
||||
title: Text(
|
||||
emisora.nombre,
|
||||
widget.emisora.nombre,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
subtitle: Text(
|
||||
[emisora.pais, emisora.idioma].where((s) => s != null).join(' · '),
|
||||
[widget.emisora.pais, widget.emisora.idioma]
|
||||
.where((s) => s != null && s.isNotEmpty)
|
||||
.join(' · '),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
trailing: _botonFavorito(theme, mini: false),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _botonFavorito(ThemeData theme, {required bool mini}) {
|
||||
return Material(
|
||||
color: mini
|
||||
? theme.colorScheme.surface.withValues(alpha: 0.8)
|
||||
: Colors.transparent,
|
||||
shape: const CircleBorder(),
|
||||
child: InkWell(
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: _toggle,
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(mini ? 6 : 4),
|
||||
child: Icon(
|
||||
_esFavorito ? Icons.favorite_rounded : Icons.favorite_outline_rounded,
|
||||
color: _esFavorito ? theme.colorScheme.error : theme.colorScheme.onSurfaceVariant,
|
||||
size: mini ? 18 : 22,
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _logo(ThemeData theme, double iconSize) {
|
||||
if (emisora.favicon != null && emisora.favicon!.isNotEmpty) {
|
||||
if (widget.emisora.favicon != null && widget.emisora.favicon!.isNotEmpty) {
|
||||
return CachedNetworkImage(
|
||||
imageUrl: emisora.favicon!,
|
||||
imageUrl: widget.emisora.favicon!,
|
||||
fit: BoxFit.cover,
|
||||
placeholder: (_, __) => _shimmer(theme),
|
||||
errorWidget: (_, __, ___) => _iconoFallback(theme, iconSize),
|
||||
|
||||
Reference in New Issue
Block a user