Restyle the Ecualizador settings screen to the new visual language while keeping the equalizer at 5 bands (spike-resolved, Engram id 2498 - band count is device-reported via just_audio's AndroidEqualizer, not app-chosen; the approved mockup's 7 sliders would silently no-op on typical hardware). - Restyle EcualizadorWidget in place: strip its internal title + preset chip row (the pushed screen's header now carries the title), add a habilitado parameter that greys/disables every slider when EQ is off. Widen PresetsEcualizadorWidget additively (personalizados param) so custom presets can join the chip row without a second implementation. - Add servicio_presets_personalizados.dart (new file, own SharedPreferences key eq_custom_presets_v1) for custom EQ preset persistence - kept out of servicio_ecualizador.dart, which has an empty-git-diff success criterion for this change. preset_ecualizador.dart is unchanged: a custom preset is just a PresetEcualizador with a user-supplied name. - Extend EstadoEcualizador with presetsPersonalizados, guardarPresetPersonalizado (validates non-empty name), eliminarPresetPersonalizado. The load is a new explicit cargarPresetsPersonalizados(), deliberately NOT folded into cargarPersistido(): that method is exercised ~30 times by estado_ecualizador_test.dart (protected, must stay unmodified) via Fakes only, with no SharedPreferences awareness in that file. - Build out the Ecualizador screen body: base-vs-per-station explainer banner, a "Salida activa" row surfaced on the main screen (previously Advanced-only), an "Emisoras con ajuste propio" drill-down sourced from the existing presetsPorEmisora map, and a "Guardar como preset" action. New coverage lives in new files rather than touching the three protected EQ test files: ecualizador_widget_test.dart (component-level, did not exist before this commit), servicio_presets_personalizados_test.dart, and estado_ecualizador_presets_personalizados_test.dart. servicio_ecualizador.dart, servicio_audio.dart and the three protected EQ test files keep an empty git diff. Full suite: 713/713 green (2 skipped, unchanged), up from 682. size:exception - realized 1,954 changed lines (25 files, plus this docs update) against the 400-550 forecast: lib/ + ARB alone is ~650 lines, near the top of the forecast band by itself since this WU also had to build out a screen body WU3a only stubbed; the rest is 4 test files (675 lines) and 11 new ARB keys regenerating 13 lib/l10n/gen files (~546 lines) - the same pattern every prior work unit in this branch has hit. Not splittable: WU14 reuses this unit's editor component by exact runtime type and cannot begin until this lands as a whole.
207 lines
7.5 KiB
Dart
207 lines
7.5 KiB
Dart
import 'package:flutter/material.dart';
|
|
|
|
import '../l10n/gen/app_localizations.dart';
|
|
import '../modelos/preset_ecualizador.dart';
|
|
import '../tema/pluriwave_theme.dart';
|
|
import 'pluri_glass_surface.dart';
|
|
|
|
class EcualizadorWidget extends StatefulWidget {
|
|
final PresetEcualizador preset;
|
|
final void Function(PresetEcualizador) onCambio;
|
|
|
|
/// Design ADR-5: greys and disables every slider when the equalizer
|
|
/// itself is off, instead of leaving fully-interactive controls that
|
|
/// silently do nothing.
|
|
final bool habilitado;
|
|
|
|
const EcualizadorWidget({
|
|
super.key,
|
|
required this.preset,
|
|
required this.onCambio,
|
|
this.habilitado = true,
|
|
});
|
|
|
|
@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);
|
|
final tokens = context.pluriTokens;
|
|
final l10n = AppLocalizations.of(context);
|
|
|
|
// Design ADR-5: the title + preset Chip row that used to live here is
|
|
// gone — the pushed screen's own 56px header carries the title now, and
|
|
// the preset chip ROW (a different, still-reusable widget,
|
|
// [PresetsEcualizadorWidget] below) is rendered by the caller alongside
|
|
// this widget instead of being duplicated inside it.
|
|
return PluriGlassSurface(
|
|
borderRadius: BorderRadius.circular(tokens.radiusLg),
|
|
padding: const EdgeInsets.all(16),
|
|
child: Row(
|
|
crossAxisAlignment: CrossAxisAlignment.end,
|
|
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
|
children: [
|
|
for (int i = 0; i < 5; i++)
|
|
Expanded(
|
|
child: AnimatedOpacity(
|
|
duration: const Duration(milliseconds: 150),
|
|
opacity: widget.habilitado ? 1.0 : 0.4,
|
|
child: Card(
|
|
color: tokens.listSurface.withValues(alpha: 0.6),
|
|
margin: const EdgeInsets.symmetric(horizontal: 4),
|
|
shape: RoundedRectangleBorder(
|
|
borderRadius: BorderRadius.circular(tokens.radiusSm),
|
|
),
|
|
child: Padding(
|
|
padding: const EdgeInsets.symmetric(
|
|
vertical: 10,
|
|
horizontal: 4,
|
|
),
|
|
child: Column(
|
|
children: [
|
|
SizedBox(
|
|
height: 152,
|
|
child: Semantics(
|
|
slider: true,
|
|
enabled: widget.habilitado,
|
|
label: l10n.equalizerBandLabel(_etiquetas[i]),
|
|
value: l10n.equalizerBandValue(
|
|
_bandas[i].toStringAsFixed(1),
|
|
),
|
|
child: RotatedBox(
|
|
quarterTurns: 3,
|
|
child: SliderTheme(
|
|
data: SliderTheme.of(context).copyWith(
|
|
trackHeight: 5,
|
|
activeTrackColor: tokens.liveGreen,
|
|
thumbColor: tokens.liveGreen,
|
|
inactiveTrackColor:
|
|
theme.colorScheme.surfaceContainerHighest,
|
|
overlayColor: tokens.liveGreen.withValues(
|
|
alpha: 0.15,
|
|
),
|
|
),
|
|
child: Slider(
|
|
value: _bandas[i],
|
|
min: -12.0,
|
|
max: 12.0,
|
|
divisions: 24,
|
|
onChanged:
|
|
widget.habilitado
|
|
? (v) => _actualizarBanda(i, v)
|
|
: null,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
Text(
|
|
'${_bandas[i].toStringAsFixed(1)}dB',
|
|
style: theme.textTheme.labelSmall?.copyWith(
|
|
color: tokens.liveGreen,
|
|
fontWeight: FontWeight.w700,
|
|
),
|
|
),
|
|
Text(
|
|
_etiquetas[i],
|
|
style: theme.textTheme.bodySmall?.copyWith(
|
|
color: theme.colorScheme.onSurfaceVariant,
|
|
),
|
|
textAlign: TextAlign.center,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
String _nombrePreset(AppLocalizations l10n, String nombre) {
|
|
return switch (nombre) {
|
|
'Flat' => l10n.equalizerPresetFlat,
|
|
'Rock' => l10n.equalizerPresetRock,
|
|
'Pop' => l10n.equalizerPresetPop,
|
|
'Bass Boost' => l10n.equalizerPresetBassBoost,
|
|
'Jazz' => l10n.equalizerPresetJazz,
|
|
'Voz' => l10n.equalizerPresetVoice,
|
|
'Personalizado' => l10n.equalizerPresetCustom,
|
|
_ => nombre,
|
|
};
|
|
}
|
|
|
|
class PresetsEcualizadorWidget extends StatelessWidget {
|
|
final PresetEcualizador presetActual;
|
|
final void Function(PresetEcualizador) onSeleccionar;
|
|
|
|
/// User-saved custom presets (WU13, `eq-custom-presets` spec), appended
|
|
/// after the 6 fixed ones. Additive-only parameter — defaults to empty so
|
|
/// this stays the same widget, not a new one (design ADR-5: "stays
|
|
/// as-is" means no restyle, not that it can never gain new data to show).
|
|
/// `_nombrePreset`'s default case already falls through to the raw name,
|
|
/// so a custom preset's chip label needs no special-casing here.
|
|
final List<PresetEcualizador> personalizados;
|
|
|
|
const PresetsEcualizadorWidget({
|
|
super.key,
|
|
required this.presetActual,
|
|
required this.onSeleccionar,
|
|
this.personalizados = const [],
|
|
});
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final theme = Theme.of(context);
|
|
final l10n = AppLocalizations.of(context);
|
|
final todos = [...PresetEcualizador.presets, ...personalizados];
|
|
return Wrap(
|
|
spacing: 8,
|
|
runSpacing: 6,
|
|
children:
|
|
todos.map((p) {
|
|
final selected = p.nombre == presetActual.nombre;
|
|
return ChoiceChip(
|
|
label: Text(_nombrePreset(l10n, p.nombre)),
|
|
selected: selected,
|
|
showCheckmark: false,
|
|
selectedColor: theme.colorScheme.primaryContainer,
|
|
backgroundColor: theme.colorScheme.surfaceContainerHighest
|
|
.withValues(alpha: 0.32),
|
|
onSelected: (_) => onSeleccionar(p),
|
|
);
|
|
}).toList(),
|
|
);
|
|
}
|
|
}
|