feat(paises): add country browser and extract shared radio transport
Extracts ServicioRadio's transport loop (server discovery, host rotation, bounded retries, User-Agent, timeout, status check, json.decode, sticky-host bookkeeping) out of `_get` into a new `_getJson(path, params) -> Future<List<dynamic>>` helper, moved as one block with no logic edits. `_get` is reimplemented on top, still owning every station-specific concern: `lastcheckok: '1'`, `Emisora.fromApi` + the empty-uuid/url filter, and the `_compararCalidad` quality sort. `_getJson` is deliberately sort-agnostic and filter-agnostic so a non-station endpoint can reuse the resilience behaviour without inheriting station-only semantics. Non-negotiable ordering followed per design ADR-4: new test/servicios/servicio_radio_transporte_test.dart characterises all 8 existing station calls (7 via `_get` plus `registrarClick`, which builds its own URI) against the UNMODIFIED `_get` first - green by construction - pinning path, lastcheckok=1, hidebroken=true, a non-empty User-Agent, exact order/reverse/limit/offset, and the exact returned UUID sequence from a fixture with deliberately shuffled bitrate/clickcount/votes. That last assertion is what makes the extraction safe: a sort that silently sank into transport would pass every other check. Re-running the same file after the extraction is byte-identical green. test/servicios/servicio_radio_test.dart is untouched by this work unit - its passing unmodified is itself a signal that transport wasn't disturbed. The 6 pre-existing `order: bitrate` occurrences (obtenerPopulares, buscarPorNombre, buscarPorPais, buscarPorIdioma, buscarPorTag, buscar) are untouched - a deliberate server-side quality bias deciding which stations return within `limit`, unrelated to and never to be confused with the user-facing "Ordenar" control, which stays entirely client-side via the existing OrdenEmisoras (Engram reference/radio-browser-sort-order). Behaviour delta, accepted per ADR-4, not a regression: moving `_servidorActual` bookkeeping into `_getJson` means a successful `/json/countries` call now warms the sticky host for subsequent station calls too - one shared warm mirror per instance, desirable, not per-call-type state. Adds the Paises browser over the verified `/json/countries` contract (Engram reference/radio-browser-countries-endpoint): new lib/modelos/pais_radio.dart (`PaisRadio.fromApi` parses `stationcount` via `int.tryParse` since the API returns it as a JSON string, not an int - an `as int` cast would throw), `obtenerPaises()` sends neither `lastcheckok` nor `order` (the screen sorts client-side by name; the API's raw byte order isn't proper collation for any locale this app ships), and inherits `hidebroken=true` from the unchanged `_uri` (desirable here too, since the endpoint's own default is false). `EstadoBusqueda` gains `paises`/`cargandoPaises`/`cargarPaises()` with an in-memory cache guard so re-entering the screen never refetches. New PantallaPaises (lib/pantallas/pantalla_paises.dart): a "Tus idiomas" shortlist (one representative country per the app's 13 supported locales, matched against the fetched list - the proposal/spec name this section but don't specify its derivation) above the full alphabetical list, each entry showing its parsed station count. Reachable from Buscar's discovery landing state via a new entry row, added now rather than left dangling per this file's own forward-reference comment (and the WU15/WU15b lesson: a fully-tested but unreachable screen is a real defect, not a follow-up). New ARB keys (en/es only, matching this change's established precedent): countriesScreenTitle, countriesYourLanguagesTitle, countriesAllTitle, radioCountriesError. Tests: 631 -> 649 (2 skipped, unchanged). flutter analyze unchanged at 1 pre-existing info. grep confirms `countrycodes` appears nowhere in lib/.
This commit is contained in:
@@ -11,8 +11,10 @@ import '../widgets/pluri_glass_surface.dart';
|
||||
import '../widgets/pluri_icon.dart';
|
||||
import '../widgets/pluri_layout.dart';
|
||||
import '../widgets/pluri_premium_widgets.dart';
|
||||
import '../widgets/pluri_push_scaffold.dart';
|
||||
import 'package:pluriwave/widgets/tarjeta_emisora.dart';
|
||||
|
||||
import 'pantalla_paises.dart';
|
||||
import 'reproducir_minimizado.dart';
|
||||
|
||||
const _paises = [
|
||||
@@ -190,6 +192,7 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
_seccionCercanas(context, theme, l10n),
|
||||
_seccionTendencias(context, theme, l10n),
|
||||
_chipGeneros(context, theme, l10n),
|
||||
_seccionPaises(context, theme, l10n),
|
||||
if (context.select<EstadoRadio, String?>((e) => e.error) != null)
|
||||
_errorBanner(
|
||||
context,
|
||||
@@ -213,21 +216,15 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
final pills = <Widget>[
|
||||
if (_paisSeleccionado != null)
|
||||
_pillFiltro(
|
||||
_paisLabelSeleccionado(l10n) ?? _paisSeleccionado!,
|
||||
() {
|
||||
setState(() => _paisSeleccionado = null);
|
||||
_buscar();
|
||||
},
|
||||
),
|
||||
_pillFiltro(_paisLabelSeleccionado(l10n) ?? _paisSeleccionado!, () {
|
||||
setState(() => _paisSeleccionado = null);
|
||||
_buscar();
|
||||
}),
|
||||
if (_idiomaSeleccionado != null)
|
||||
_pillFiltro(
|
||||
_idiomaLabelSeleccionado(l10n) ?? _idiomaSeleccionado!,
|
||||
() {
|
||||
setState(() => _idiomaSeleccionado = null);
|
||||
_buscar();
|
||||
},
|
||||
),
|
||||
_pillFiltro(_idiomaLabelSeleccionado(l10n) ?? _idiomaSeleccionado!, () {
|
||||
setState(() => _idiomaSeleccionado = null);
|
||||
_buscar();
|
||||
}),
|
||||
if (_calidadMinima != null)
|
||||
_pillFiltro('≥$_calidadMinima kbps', () {
|
||||
setState(() => _calidadMinima = null);
|
||||
@@ -249,7 +246,8 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (pills.isNotEmpty) Wrap(spacing: 8, runSpacing: 8, children: pills),
|
||||
if (pills.isNotEmpty)
|
||||
Wrap(spacing: 8, runSpacing: 8, children: pills),
|
||||
if (pills.isNotEmpty && estado.resultados.isNotEmpty)
|
||||
const SizedBox(height: 10),
|
||||
if (!estado.cargando && estado.resultados.isNotEmpty)
|
||||
@@ -438,9 +436,7 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
selected: seleccionado == value,
|
||||
visualDensity: VisualDensity.compact,
|
||||
onSelected:
|
||||
(_) => onChanged(
|
||||
seleccionado == value ? null : value,
|
||||
),
|
||||
(_) => onChanged(seleccionado == value ? null : value),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -486,9 +482,7 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
selected: seleccionado == value,
|
||||
visualDensity: VisualDensity.compact,
|
||||
onSelected:
|
||||
(_) => onChanged(
|
||||
seleccionado == value ? null : value,
|
||||
),
|
||||
(_) => onChanged(seleccionado == value ? null : value),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -527,7 +521,9 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
child: PluriEmptyState(
|
||||
glyph: PluriIconGlyph.search,
|
||||
title:
|
||||
sinFiltros ? l10n.searchEmptyTitle : l10n.searchNoResultsTitle,
|
||||
sinFiltros
|
||||
? l10n.searchEmptyTitle
|
||||
: l10n.searchNoResultsTitle,
|
||||
subtitle:
|
||||
sinFiltros
|
||||
? l10n.searchEmptySubtitle
|
||||
@@ -803,6 +799,46 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
);
|
||||
}
|
||||
|
||||
/// WU7, `station-discovery-browse` spec: the "Países entry point" the
|
||||
/// spec's landing-state scenario lists. Deferred from WU6 (this class's
|
||||
/// own doc comment: `PantallaPaises` did not exist yet); added here now
|
||||
/// that it does, alongside the screen it targets — an unreachable screen
|
||||
/// would repeat the WU15/WU15b lesson (a fully-tested screen shipped with
|
||||
/// no navigation path to it).
|
||||
Widget _seccionPaises(
|
||||
BuildContext context,
|
||||
ThemeData theme,
|
||||
AppLocalizations l10n,
|
||||
) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(
|
||||
PluriLayout.horizontal,
|
||||
8,
|
||||
PluriLayout.horizontal,
|
||||
0,
|
||||
),
|
||||
child: PluriGlassSurface(
|
||||
padding: EdgeInsets.zero,
|
||||
// `PluriGlassSurface` paints via `DecoratedBox`, not `Material` — a
|
||||
// tappable `ListTile` needs its own `Material` ancestor or its ink
|
||||
// splash silently fails to paint (Flutter's own debug assertion).
|
||||
child: Material(
|
||||
type: MaterialType.transparency,
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.public_rounded),
|
||||
title: Text(l10n.countriesScreenTitle),
|
||||
trailing: const Icon(Icons.chevron_right_rounded),
|
||||
onTap:
|
||||
() => PluriPushScaffold.push(
|
||||
context,
|
||||
(_) => const PantallaPaises(),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _errorBanner(
|
||||
BuildContext context,
|
||||
String error,
|
||||
@@ -892,7 +928,11 @@ class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||
(context, i) => TarjetaEmisora(
|
||||
emisora: emisoras[i],
|
||||
onTap: () => reproducirMinimizado(context, emisoras[i]),
|
||||
).pluriFadeSlideIn(context, delay: Duration(milliseconds: i * 30), beginY: 0.1),
|
||||
).pluriFadeSlideIn(
|
||||
context,
|
||||
delay: Duration(milliseconds: i * 30),
|
||||
beginY: 0.1,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user