Compare commits
10 Commits
feature/bd
...
4764266a1a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4764266a1a | ||
| 7044cc0b2a | |||
| 9aa881342d | |||
|
|
ac5ab2316f | ||
|
|
81db383a47 | ||
|
|
e9d1f67aa4 | ||
|
|
25a3f3cf5a | ||
|
|
2fe1d60e23 | ||
|
|
76f1b4ce2d | ||
|
|
64f6e37373 |
66
.gitea/workflows/ci.yml
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
name: Flutter CI/CD — PluriWave
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
pull_request:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
flutter-ci:
|
||||||
|
name: Test + Build
|
||||||
|
runs-on: macmini-flutter
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
- name: Flutter pub get
|
||||||
|
run: flutter pub get
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: flutter test
|
||||||
|
|
||||||
|
- name: Build APK (release)
|
||||||
|
run: flutter build apk --release
|
||||||
|
|
||||||
|
- name: Build AppBundle (release)
|
||||||
|
run: flutter build appbundle --release
|
||||||
|
|
||||||
|
- name: Upload APK artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: pluriwave-apk-${{ gitea.sha }}
|
||||||
|
path: build/app/outputs/apk/release/app-release.apk
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
- name: Upload AppBundle artifact
|
||||||
|
uses: actions/upload-artifact@v4
|
||||||
|
with:
|
||||||
|
name: pluriwave-aab-${{ gitea.sha }}
|
||||||
|
path: build/app/outputs/bundle/release/app-release.aab
|
||||||
|
if-no-files-found: error
|
||||||
|
|
||||||
|
- name: Notify Telegram — éxito
|
||||||
|
if: success()
|
||||||
|
run: |
|
||||||
|
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||||
|
-d chat_id="${TELEGRAM_CHAT_ID}" \
|
||||||
|
-d parse_mode="HTML" \
|
||||||
|
-d text="✅ <b>PluriWave CI OK</b>%0ABranch: <code>${{ gitea.ref_name }}</code>%0ACommit: <code>${{ gitea.sha }}</code>%0AAPKs subidos como artifacts en Gitea."
|
||||||
|
env:
|
||||||
|
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||||
|
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||||
|
|
||||||
|
- name: Notify Telegram — fallo
|
||||||
|
if: failure()
|
||||||
|
run: |
|
||||||
|
curl -s -X POST "https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage" \
|
||||||
|
-d chat_id="${TELEGRAM_CHAT_ID}" \
|
||||||
|
-d parse_mode="HTML" \
|
||||||
|
-d text="❌ <b>PluriWave CI FALLÓ</b>%0ABranch: <code>${{ gitea.ref_name }}</code>%0ACommit: <code>${{ gitea.sha }}</code>%0ARevisa el log en Gitea."
|
||||||
|
env:
|
||||||
|
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }}
|
||||||
|
TELEGRAM_CHAT_ID: ${{ secrets.TELEGRAM_CHAT_ID }}
|
||||||
143
ARQ-REVISION-F1.md
Normal file
@@ -0,0 +1,143 @@
|
|||||||
|
# Revisión Arquitectura — PluriWave Fase 1
|
||||||
|
**Arq | 2026-04-04**
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Decisión: stack APROBADO con ajustes menores
|
||||||
|
|
||||||
|
El stack propuesto es sólido para una app de radio Flutter. Sin conflictos bloqueantes de dependencias. Sin problemas de licencia.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Stack analizado
|
||||||
|
|
||||||
|
| Paquete | Versión declarada | Latest | Licencia |
|
||||||
|
|---------|------------------|--------|----------|
|
||||||
|
| `just_audio` | `^0.9.42` | 0.10.5 | Apache-2.0 + MIT ✅ |
|
||||||
|
| `audio_service` | `^0.18.15` | 0.18.18 | MIT ✅ |
|
||||||
|
| `audio_session` | `^0.1.21` | 0.2.3 | N/A (OSI) ✅ |
|
||||||
|
| `sqflite` | `^2.4.1` | 2.4.2 | BSD-2 ✅ |
|
||||||
|
| `flutter_animate` | `^4.5.2` | 4.5.2 | BSD-3 ✅ |
|
||||||
|
| `google_mobile_ads` | comentado | 7.0.0 | Apache-2.0 ✅ |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Análisis de compatibilidad de versiones
|
||||||
|
|
||||||
|
### Dependencia crítica: `audio_session`
|
||||||
|
|
||||||
|
Tres paquetes compiten por `audio_session`:
|
||||||
|
|
||||||
|
- `just_audio 0.9.42` requiere: `^0.1.14` → ≥0.1.14 <0.2.0
|
||||||
|
- `audio_service 0.18.15` requiere: `^0.1.20` → ≥0.1.20 <0.2.0
|
||||||
|
- `pubspec.yaml` declara: `^0.1.21` → ≥0.1.21 <0.2.0
|
||||||
|
|
||||||
|
**Intersección**: ≥0.1.21 <0.2.0 → disponibles hasta 0.1.25 → **SIN CONFLICTO ✅**
|
||||||
|
|
||||||
|
### `rxdart`
|
||||||
|
|
||||||
|
Ambos paquetes requieren `>=0.26.0 <0.29.0`. rxdart latest es 0.28.0. **SIN CONFLICTO ✅**
|
||||||
|
|
||||||
|
### `js` (dep transitiva de `audio_service`)
|
||||||
|
|
||||||
|
`audio_service` requiere `js >=0.6.3 <0.8.0`. Esto es solo para la plataforma web. Si no hay web target, es irrelevante. Si en el futuro se añade web: aceptable, `js 0.7.2` es la latest en ese rango.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Ajustes recomendados
|
||||||
|
|
||||||
|
### 🟠 1. Actualizar `just_audio` a `^0.10.0` (importante)
|
||||||
|
|
||||||
|
`just_audio 0.9.x` está en mantenimiento. La rama `0.10.x` (latest: 0.10.5) tiene:
|
||||||
|
- Soporte Flutter ≥3.27.0 (el runner macmini-flutter probablemente lo cumple)
|
||||||
|
- API compatible para streaming de radio (URLs HTTP/HTTPS directas)
|
||||||
|
- `audio_session` requiere `>=0.1.24 <0.3.0` con 0.10.x — compatible con la gama completa
|
||||||
|
|
||||||
|
**Acción**: cambiar `just_audio: ^0.9.42` → `just_audio: ^0.10.0` en pubspec.yaml.
|
||||||
|
Si el runner tiene Flutter <3.27.0, mantener 0.9.42.
|
||||||
|
|
||||||
|
### 🟡 2. Actualizar `audio_service` a `^0.18.18` (menor)
|
||||||
|
|
||||||
|
La 0.18.18 actualiza `audio_session` a `>=0.1.25 <0.3.0`, lo que permite usar versiones 0.2.x en el futuro sin romper nada.
|
||||||
|
|
||||||
|
### 🟡 3. `google_mobile_ads` — descomentarlo con cuidado
|
||||||
|
|
||||||
|
Actualmente comentado (correcto para Fase 1). Cuando se active:
|
||||||
|
- Usar `^5.3.0` (ya declarado) si el runner tiene Flutter ≥3.7.0 — ✅
|
||||||
|
- **Evitar `^7.0.0`** por ahora: requiere actualización de `compileSdk` en Android y puede romper el CI
|
||||||
|
- Necesitará `ad_unit_id` real en secrets de CI antes de activar en release builds
|
||||||
|
- Play Store requiere declarar uso de datos de anuncios en el Data Safety form
|
||||||
|
|
||||||
|
### 🔴 4. Signing config para release builds — BLOQUEANTE para CI
|
||||||
|
|
||||||
|
`android/app/build.gradle.kts` tiene:
|
||||||
|
```kotlin
|
||||||
|
signingConfig = signingConfigs.getByName("debug") // TODO: fix
|
||||||
|
```
|
||||||
|
|
||||||
|
Esto firma el APK/AAB release con la clave debug. **No es aceptable para Play Store**, pero sí funciona para artifacts internos de CI (distribución interna, testing).
|
||||||
|
|
||||||
|
Para CI de Fase 1: aceptable como está.
|
||||||
|
Para producción: añadir keystore como secret en Gitea CI y configurar signing real.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Estructura de app — observación
|
||||||
|
|
||||||
|
`lib/main.dart` es el scaffold por defecto de Flutter (contador demo). Los devs deberán reemplazarlo con la arquitectura real de PluriWave antes de que los tests sean útiles.
|
||||||
|
|
||||||
|
Sugerencia de estructura para Fase 1:
|
||||||
|
|
||||||
|
```
|
||||||
|
lib/
|
||||||
|
├── main.dart
|
||||||
|
├── app.dart # MaterialApp + Provider setup
|
||||||
|
├── core/
|
||||||
|
│ ├── servicios/
|
||||||
|
│ │ ├── servicio_audio.dart # just_audio + audio_service wrapper
|
||||||
|
│ │ └── servicio_radio.dart # fetch streams/stations API
|
||||||
|
│ └── db/
|
||||||
|
│ └── db_helper.dart # sqflite setup
|
||||||
|
├── modelos/
|
||||||
|
│ ├── emisora.dart
|
||||||
|
│ └── favorito.dart
|
||||||
|
└── ui/
|
||||||
|
├── pantalla_inicio.dart
|
||||||
|
├── pantalla_reproductor.dart
|
||||||
|
└── widgets/
|
||||||
|
```
|
||||||
|
|
||||||
|
`Provider` (ya en pubspec) es correcto para este scope. No hace falta Riverpod ni Bloc para Fase 1.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Licencias — veredicto
|
||||||
|
|
||||||
|
| Paquete | Licencia | Uso comercial | Distribución |
|
||||||
|
|---------|----------|--------------|-------------|
|
||||||
|
| `just_audio` | Apache-2.0 + MIT | ✅ libre | ✅ libre |
|
||||||
|
| `audio_service` | MIT | ✅ libre | ✅ libre |
|
||||||
|
| `sqflite` | BSD-2 | ✅ libre | ✅ libre |
|
||||||
|
| `flutter_animate` | BSD-3 | ✅ libre | ✅ libre |
|
||||||
|
| `google_mobile_ads` | Apache-2.0 | ✅ (con cuenta AdMob) | ✅ libre |
|
||||||
|
|
||||||
|
Sin restricciones de licencia para app comercial en Play Store. ✅
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Resumen ejecutivo
|
||||||
|
|
||||||
|
| Ítem | Estado |
|
||||||
|
|------|--------|
|
||||||
|
| Conflictos de dependencias | ✅ Ninguno |
|
||||||
|
| Licencias incompatibles | ✅ Ninguna |
|
||||||
|
| Stack adecuado para radio en streaming | ✅ Sí |
|
||||||
|
| Signing release para Play Store | ⚠️ Pendiente (keystore) |
|
||||||
|
| just_audio versión óptima | 🟠 Actualizar a ^0.10.0 si Flutter ≥3.27 |
|
||||||
|
| google_mobile_ads | 🟡 Descomentarlo solo cuando haya Ad Unit IDs reales |
|
||||||
|
| Estructura de código | 🟡 Scaffold vacío — devs deben estructurar lib/ |
|
||||||
|
|
||||||
|
**El stack puede profundizarse sin riesgo. Sin bloqueos.**
|
||||||
|
|
||||||
|
---
|
||||||
|
*Arq — revisión sin acceso al analisis.md de Obsidian (fichero no sincronizado localmente). Revisión realizada directamente desde pub.dev API + pubspec.yaml del repo.*
|
||||||
46
CHANGELOG.md
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
# Changelog — PluriWave
|
||||||
|
|
||||||
|
## [0.4.0] — 2026-04-04
|
||||||
|
|
||||||
|
### Añadido
|
||||||
|
- **PantallaReproductor** — pantalla completa del reproductor. Accesible tocando MiniReproductor o cualquier emisora. Incluye: artwork/logo grande con sombra animada al reproducir, nombre + chips info (país, idioma), codec/bitrate, controles play/pause/stop con indicador "en vivo", botón favorito (toggle), widget de timer (iniciar/cancelar desde la pantalla), animación de entrada slide-up. Transición pageRoute desde cualquier pantalla.
|
||||||
|
- **PantallaAjustes** — pantalla de ajustes básica (tab nuevo en NavigationBar). Muestra estado del sistema (filtro emisoras, audio background), conteo de favoritos, preview de features próximas (Export/Import, radio personalizada, ecualizador).
|
||||||
|
- **MiniReproductor** — ahora es tappable: toca la barra para abrir PantallaReproductor.
|
||||||
|
- **NavigationBar** — añadido tab "Ajustes" (4 destinos: Inicio/Buscar/Favoritos/Ajustes).
|
||||||
|
|
||||||
|
## [0.3.0] — 2026-04-04
|
||||||
|
|
||||||
|
### Fixes (prioridad alta — petición WhikY)
|
||||||
|
|
||||||
|
- **Audio en background** — `ServicioAudio` refactorizado para delegar toda la reproducción a `PluriWaveAudioHandler` (audio_service). La notificación foreground de Android mantiene el audio vivo al apagar pantalla. Handler inicializado en `main.dart` con `AudioService.init()` y registrado globalmente. `onTaskRemoved` libera recursos al cerrar la app. `mediaItem` propagado con nombre, artista y artwork de la emisora.
|
||||||
|
- **Filtrar emisoras rotas** — `ServicioRadio` añade `lastcheckok=1` en todas las peticiones a la API. Solo se devuelven emisoras verificadas como funcionales por Radio Browser.
|
||||||
|
- **Errores como SnackBar** — `EstadoRadio` emite errores de reproducción y búsqueda por `errorStream` (StreamController broadcast). `_PaginaPrincipalState.didChangeDependencies` suscribe al stream y muestra `SnackBar` flotante de 3 segundos. Los errores de carga de lista siguen como banner inline (no bloquean la UI).
|
||||||
|
- **Icono de app** — Generado con Stable Diffusion XL: diseño morado, ondas de radio blancas, estilo Material You. Todos los tamaños Android generados (mdpi/hdpi/xhdpi/xxhdpi/xxxhdpi, 48-192px). `ic_launcher_round` añadido. `android:roundIcon` en AndroidManifest.
|
||||||
|
|
||||||
|
### Ficheros modificados
|
||||||
|
| Fichero | Cambio |
|
||||||
|
|---|---|
|
||||||
|
| `lib/main.dart` | `AudioService.init()` + `registrarHandler()` |
|
||||||
|
| `lib/servicios/servicio_audio.dart` | Arquitectura background completa |
|
||||||
|
| `lib/servicios/servicio_radio.dart` | `lastcheckok=1` en todas las peticiones |
|
||||||
|
| `lib/estado/estado_radio.dart` | `errorStream` en lugar de campo `_error` |
|
||||||
|
| `lib/app.dart` | Listener `errorStream` → SnackBar + theme SnackBar |
|
||||||
|
| `android/app/src/main/AndroidManifest.xml` | `roundIcon` |
|
||||||
|
| `android/app/src/main/res/mipmap-*/` | Iconos generados (5 densidades) |
|
||||||
|
|
||||||
|
## [0.2.0] — 2026-04-04
|
||||||
|
|
||||||
|
### Añadido
|
||||||
|
- **CI/CD Gitea Actions** — workflow `.gitea/workflows/ci.yml` para el runner `macmini-flutter`. Jobs en secuencia: `flutter pub get` → `flutter test` → `flutter build apk --release` → `flutter build appbundle --release`. APK y AAB subidos como artifacts con el SHA del commit en el nombre (`pluriwave-apk-<sha>`, `pluriwave-aab-<sha>`). Notificación Telegram al finalizar: ✅ éxito con commit y rama, ❌ fallo con enlace al log. Activado en push a `main` y PRs contra `main`.
|
||||||
|
- **`ARQ-REVISION-F1.md`** — revisión de arquitectura del stack Flutter. Veredicto: aprobado. Sin conflictos de dependencias (`audio_session` compartido entre `just_audio` y `audio_service` sin colisión; `rxdart` sin conflicto). Todas las licencias OSI-approved (MIT, Apache-2.0, BSD). Ajustes pendientes: actualizar `just_audio` a ^0.10.0 con Flutter ≥3.27.0, signing real para Play Store, `google_mobile_ads` comentado hasta tener Ad Unit IDs.
|
||||||
|
|
||||||
|
### Notas técnicas
|
||||||
|
- **Signing**: `build.gradle.kts` usa clave debug para release (TODO preexistente). Válido para CI interno y testing. Play Store requiere keystore como secret en Gitea.
|
||||||
|
- **Secrets necesarios**: `TELEGRAM_BOT_TOKEN` y `TELEGRAM_CHAT_ID` (Settings → Secrets del repo en Gitea).
|
||||||
|
|
||||||
|
### Ficheros añadidos
|
||||||
|
| Fichero | Descripción |
|
||||||
|
|---|---|
|
||||||
|
| `.gitea/workflows/ci.yml` | Workflow CI/CD Flutter completo (+66 líneas) |
|
||||||
|
| `ARQ-REVISION-F1.md` | Revisión arquitectura F1 — stack, licencias, ajustes (+143 líneas) |
|
||||||
|
|
||||||
39
README.md
@@ -1,17 +1,17 @@
|
|||||||
# 📻 PluriWave
|
# PluriWave
|
||||||
|
|
||||||
Radio mundial con ecualizador personalizable, reconocimiento de canciones y UI premium.
|
Radio mundial con ecualizador personalizable, reconocimiento de canciones y UI premium.
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- 🌍 **+53.000 emisoras** de 238 países (Radio Browser API)
|
- **+53.000 emisoras** de 238 países (Radio Browser API)
|
||||||
- 🎛️ **Ecualizador por emisora** — guarda tu preset favorito para cada radio
|
- **Ecualizador por emisora** — guarda tu preset favorito para cada radio
|
||||||
- 🎵 **Reconocimiento de canciones** — "¿Qué suena?" sin salir de la app
|
- **Reconocimiento de canciones** — "¿Qué suena?" sin salir de la app
|
||||||
- ⏰ **Timer de auto-apagado** — perfecto para dormir
|
- **Timer de auto-apagado** — perfecto para dormir
|
||||||
- 🔊 **Reproducción en segundo plano** — sigue sonando con la pantalla apagada
|
- **Reproducción en segundo plano** — sigue sonando con la pantalla apagada
|
||||||
- ⭐ **Favoritos** — accede rápido a tus emisoras preferidas
|
- **Favoritos** — acceso rápido a emisoras preferidas
|
||||||
- 📤 **Compartir** — envía emisoras a tus amigos
|
- **Compartir** — envía emisoras a tus amigos
|
||||||
- 🎨 **UI premium** — Material You, visualizador de audio, animaciones fluidas
|
- **UI premium** — Material You, visualizador de audio, animaciones fluidas
|
||||||
|
|
||||||
## Monetización
|
## Monetización
|
||||||
|
|
||||||
@@ -22,13 +22,31 @@ Radio mundial con ecualizador personalizable, reconocimiento de canciones y UI p
|
|||||||
## Stack
|
## Stack
|
||||||
|
|
||||||
- **Frontend**: Flutter (Android + iOS)
|
- **Frontend**: Flutter (Android + iOS)
|
||||||
- **Radio API**: [Radio Browser](https://api.radio-browser.info/) (gratis, +53K emisoras)
|
- **Radio API**: Radio Browser (gratis, +53K emisoras)
|
||||||
- **Audio**: just_audio + audio_service
|
- **Audio**: just_audio + audio_service
|
||||||
- **Ecualizador**: just_audio equalizer (Android nativo)
|
- **Ecualizador**: just_audio equalizer (Android nativo)
|
||||||
- **Reconocimiento**: AudD API (1000 req/mes free)
|
- **Reconocimiento**: AudD API (1000 req/mes free)
|
||||||
- **Ads**: Google AdMob
|
- **Ads**: Google AdMob
|
||||||
- **Compras**: in_app_purchase
|
- **Compras**: in_app_purchase
|
||||||
|
|
||||||
|
## CI/CD
|
||||||
|
|
||||||
|
Workflow Gitea Actions en `.gitea/workflows/ci.yml`, runner `macmini-flutter`.
|
||||||
|
|
||||||
|
**Jobs:** `flutter pub get` → `flutter test` → `build apk --release` → `build appbundle --release`
|
||||||
|
|
||||||
|
**Artifacts:** APK y AAB guardados en Gitea con nombre `pluriwave-apk-<sha>` / `pluriwave-aab-<sha>`.
|
||||||
|
|
||||||
|
**Notificaciones:** Telegram al completar (éxito ✅ / fallo ❌).
|
||||||
|
|
||||||
|
**Secrets necesarios en el repo:**
|
||||||
|
| Secret | Uso |
|
||||||
|
|---|---|
|
||||||
|
| `TELEGRAM_BOT_TOKEN` | Notificaciones CI |
|
||||||
|
| `TELEGRAM_CHAT_ID` | Canal de destino |
|
||||||
|
|
||||||
|
> **Signing**: build de release usa clave debug (válido para CI interno). Para Play Store se requiere keystore como secret adicional.
|
||||||
|
|
||||||
## Desarrollador
|
## Desarrollador
|
||||||
|
|
||||||
FreeTimeLab — [freetimelab.es](https://freetimelab.es)
|
FreeTimeLab — [freetimelab.es](https://freetimelab.es)
|
||||||
@@ -36,3 +54,4 @@ FreeTimeLab — [freetimelab.es](https://freetimelab.es)
|
|||||||
## Licencia
|
## Licencia
|
||||||
|
|
||||||
MIT
|
MIT
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<!-- Permisos requeridos para streaming de audio -->
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"/>
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
|
||||||
|
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_MEDIA_PLAYBACK"/>
|
||||||
|
<uses-permission android:name="android.permission.WAKE_LOCK"/>
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:label="pluriwave"
|
android:label="PluriWave"
|
||||||
android:name="${applicationName}"
|
android:name="${applicationName}"
|
||||||
android:icon="@mipmap/ic_launcher">
|
android:icon="@mipmap/ic_launcher"
|
||||||
|
android:roundIcon="@mipmap/ic_launcher_round">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:exported="true"
|
android:exported="true"
|
||||||
@@ -12,10 +19,6 @@
|
|||||||
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
|
||||||
android:hardwareAccelerated="true"
|
android:hardwareAccelerated="true"
|
||||||
android:windowSoftInputMode="adjustResize">
|
android:windowSoftInputMode="adjustResize">
|
||||||
<!-- Specifies an Android theme to apply to this Activity as soon as
|
|
||||||
the Android process has started. This theme is visible to the user
|
|
||||||
while the Flutter UI initializes. After that, this theme continues
|
|
||||||
to determine the Window background behind the Flutter UI. -->
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="io.flutter.embedding.android.NormalTheme"
|
android:name="io.flutter.embedding.android.NormalTheme"
|
||||||
android:resource="@style/NormalTheme"
|
android:resource="@style/NormalTheme"
|
||||||
@@ -25,17 +28,30 @@
|
|||||||
<category android:name="android.intent.category.LAUNCHER"/>
|
<category android:name="android.intent.category.LAUNCHER"/>
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
</activity>
|
</activity>
|
||||||
<!-- Don't delete the meta-data below.
|
|
||||||
This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
|
<!-- Servicio de audio en background (audio_service) -->
|
||||||
|
<service
|
||||||
|
android:name="com.ryanheise.audioservice.AudioService"
|
||||||
|
android:foregroundServiceType="mediaPlayback"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.media.browse.MediaBrowserService"/>
|
||||||
|
</intent-filter>
|
||||||
|
</service>
|
||||||
|
|
||||||
|
<!-- Receptor de controles de media (auriculares, notificación) -->
|
||||||
|
<receiver
|
||||||
|
android:name="com.ryanheise.audioservice.MediaButtonReceiver"
|
||||||
|
android:exported="true">
|
||||||
|
<intent-filter>
|
||||||
|
<action android:name="android.intent.action.MEDIA_BUTTON"/>
|
||||||
|
</intent-filter>
|
||||||
|
</receiver>
|
||||||
|
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="flutterEmbedding"
|
android:name="flutterEmbedding"
|
||||||
android:value="2" />
|
android:value="2" />
|
||||||
</application>
|
</application>
|
||||||
<!-- Required to query activities that can process text, see:
|
|
||||||
https://developer.android.com/training/package-visibility and
|
|
||||||
https://developer.android.com/reference/android/content/Intent#ACTION_PROCESS_TEXT.
|
|
||||||
|
|
||||||
In particular, this is used by the Flutter engine in io.flutter.plugin.text.ProcessTextPlugin. -->
|
|
||||||
<queries>
|
<queries>
|
||||||
<intent>
|
<intent>
|
||||||
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
<action android:name="android.intent.action.PROCESS_TEXT"/>
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 544 B After Width: | Height: | Size: 3.2 KiB |
BIN
android/app/src/main/res/mipmap-hdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 442 B After Width: | Height: | Size: 2.0 KiB |
BIN
android/app/src/main/res/mipmap-mdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
|
Before Width: | Height: | Size: 721 B After Width: | Height: | Size: 4.6 KiB |
BIN
android/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 4.6 KiB |
|
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 8.5 KiB |
BIN
android/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 13 KiB |
BIN
android/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
assets/images/ic_launcher_source.png
Normal file
|
After Width: | Height: | Size: 89 KiB |
196
lib/app.dart
Normal file
@@ -0,0 +1,196 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:google_fonts/google_fonts.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'estado/estado_radio.dart';
|
||||||
|
import 'pantallas/pantalla_inicio.dart';
|
||||||
|
import 'pantallas/pantalla_buscar.dart';
|
||||||
|
import 'pantallas/pantalla_favoritos.dart';
|
||||||
|
import 'pantallas/pantalla_ajustes.dart';
|
||||||
|
import 'widgets/mini_reproductor.dart';
|
||||||
|
|
||||||
|
class PluriWaveApp extends StatelessWidget {
|
||||||
|
const PluriWaveApp({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return ChangeNotifierProvider(
|
||||||
|
create: (_) => EstadoRadio(),
|
||||||
|
child: MaterialApp(
|
||||||
|
title: 'PluriWave',
|
||||||
|
debugShowCheckedModeBanner: false,
|
||||||
|
theme: _buildTheme(Brightness.dark),
|
||||||
|
darkTheme: _buildTheme(Brightness.dark),
|
||||||
|
themeMode: ThemeMode.dark,
|
||||||
|
home: const _PaginaPrincipal(),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
ThemeData _buildTheme(Brightness brightness) {
|
||||||
|
final colorScheme = ColorScheme.fromSeed(
|
||||||
|
seedColor: const Color(0xFF6750A4),
|
||||||
|
brightness: brightness,
|
||||||
|
);
|
||||||
|
return ThemeData(
|
||||||
|
useMaterial3: true,
|
||||||
|
colorScheme: colorScheme,
|
||||||
|
textTheme: GoogleFonts.interTextTheme(
|
||||||
|
ThemeData(brightness: brightness).textTheme,
|
||||||
|
),
|
||||||
|
cardTheme: CardTheme(
|
||||||
|
elevation: 0,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
|
||||||
|
color: colorScheme.surfaceContainerLow,
|
||||||
|
),
|
||||||
|
snackBarTheme: SnackBarThemeData(
|
||||||
|
behavior: SnackBarBehavior.floating,
|
||||||
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(8)),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PaginaPrincipal extends StatefulWidget {
|
||||||
|
const _PaginaPrincipal();
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<_PaginaPrincipal> createState() => _PaginaPrincipalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PaginaPrincipalState extends State<_PaginaPrincipal> {
|
||||||
|
int _indice = 0;
|
||||||
|
|
||||||
|
static const _paginas = [
|
||||||
|
PantallaInicio(),
|
||||||
|
PantallaBuscar(),
|
||||||
|
PantallaFavoritos(),
|
||||||
|
PantallaAjustes(),
|
||||||
|
];
|
||||||
|
|
||||||
|
static const _destinos = [
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.home_outlined),
|
||||||
|
selectedIcon: Icon(Icons.home),
|
||||||
|
label: 'Inicio',
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.search_outlined),
|
||||||
|
selectedIcon: Icon(Icons.search),
|
||||||
|
label: 'Buscar',
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.favorite_outline),
|
||||||
|
selectedIcon: Icon(Icons.favorite),
|
||||||
|
label: 'Favoritos',
|
||||||
|
),
|
||||||
|
NavigationDestination(
|
||||||
|
icon: Icon(Icons.settings_outlined),
|
||||||
|
selectedIcon: Icon(Icons.settings),
|
||||||
|
label: 'Ajustes',
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeDependencies() {
|
||||||
|
super.didChangeDependencies();
|
||||||
|
context.read<EstadoRadio>().errorStream.listen((msg) {
|
||||||
|
if (!mounted) return;
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(msg),
|
||||||
|
duration: const Duration(seconds: 3),
|
||||||
|
action: SnackBarAction(label: 'OK', onPressed: () {}),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Scaffold(
|
||||||
|
appBar: _indice == 3
|
||||||
|
? null // PantallaAjustes tiene su propio AppBar
|
||||||
|
: AppBar(
|
||||||
|
title: const Text('PluriWave'),
|
||||||
|
actions: [
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.bedtime_outlined),
|
||||||
|
tooltip: 'Timer de sueño',
|
||||||
|
onPressed: () => _mostrarTimerDialog(context),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: _paginas[_indice],
|
||||||
|
bottomNavigationBar: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
const MiniReproductor(),
|
||||||
|
NavigationBar(
|
||||||
|
selectedIndex: _indice,
|
||||||
|
onDestinationSelected: (i) => setState(() => _indice = i),
|
||||||
|
destinations: _destinos,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _mostrarTimerDialog(BuildContext context) {
|
||||||
|
final estado = context.read<EstadoRadio>();
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('Timer de sueño', style: Theme.of(ctx).textTheme.titleLarge),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
if (estado.timer.activo)
|
||||||
|
StreamBuilder<Duration>(
|
||||||
|
stream: estado.timer.tiempoRestanteStream,
|
||||||
|
builder: (ctx, snap) {
|
||||||
|
final t = snap.data ?? Duration.zero;
|
||||||
|
final h = t.inHours;
|
||||||
|
final m = t.inMinutes.remainder(60).toString().padLeft(2, '0');
|
||||||
|
final s = t.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
'${h > 0 ? "${h}h " : ""}${m}m ${s}s',
|
||||||
|
style: Theme.of(ctx).textTheme.headlineMedium,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
FilledButton.tonal(
|
||||||
|
onPressed: () {
|
||||||
|
estado.cancelarTimer();
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
},
|
||||||
|
child: const Text('Cancelar timer'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
children: [15, 30, 60, 90]
|
||||||
|
.map((min) => ActionChip(
|
||||||
|
label: Text('$min min'),
|
||||||
|
onPressed: () {
|
||||||
|
estado.iniciarTimer(min);
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
144
lib/estado/estado_radio.dart
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import '../modelos/emisora.dart';
|
||||||
|
import '../servicios/servicio_audio.dart';
|
||||||
|
import '../servicios/servicio_favoritos.dart';
|
||||||
|
import '../servicios/servicio_radio.dart';
|
||||||
|
import '../servicios/servicio_timer.dart';
|
||||||
|
|
||||||
|
/// Estado global de la app con ChangeNotifier (Provider).
|
||||||
|
///
|
||||||
|
/// Errores de reproducción se emiten por [errorStream] para mostrar como
|
||||||
|
/// SnackBar — no bloquean la UI.
|
||||||
|
class EstadoRadio extends ChangeNotifier {
|
||||||
|
final ServicioAudio audio = ServicioAudio();
|
||||||
|
final ServicioFavoritos favoritos = ServicioFavoritos();
|
||||||
|
final ServicioRadio radio = ServicioRadio();
|
||||||
|
late final ServicioTimer timer;
|
||||||
|
|
||||||
|
// Errores de reproducción → SnackBar en el UI
|
||||||
|
final _errorController = StreamController<String>.broadcast();
|
||||||
|
Stream<String> get errorStream => _errorController.stream;
|
||||||
|
|
||||||
|
List<Emisora> _populares = [];
|
||||||
|
List<Emisora> _tendencias = [];
|
||||||
|
List<Emisora> _resultadosBusqueda = [];
|
||||||
|
List<Emisora> _listafavoritos = [];
|
||||||
|
|
||||||
|
bool _cargandoPopulares = false;
|
||||||
|
bool _cargandoBusqueda = false;
|
||||||
|
String? _errorCarga; // solo para errores de carga de lista (banner estático)
|
||||||
|
|
||||||
|
EstadoRadio() {
|
||||||
|
timer = ServicioTimer(audio);
|
||||||
|
_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Emisora> get populares => _populares;
|
||||||
|
List<Emisora> get tendencias => _tendencias;
|
||||||
|
List<Emisora> get resultadosBusqueda => _resultadosBusqueda;
|
||||||
|
List<Emisora> get listaFavoritos => _listafavoritos;
|
||||||
|
bool get cargandoPopulares => _cargandoPopulares;
|
||||||
|
bool get cargandoBusqueda => _cargandoBusqueda;
|
||||||
|
String? get error => _errorCarga;
|
||||||
|
Emisora? get emisoraActual => audio.emisoraActual;
|
||||||
|
Stream<EstadoReproduccion> get estadoStream => audio.estadoStream;
|
||||||
|
|
||||||
|
Future<void> _init() async {
|
||||||
|
await Future.wait([
|
||||||
|
cargarPopulares(),
|
||||||
|
cargarFavoritos(),
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> cargarPopulares() async {
|
||||||
|
_cargandoPopulares = true;
|
||||||
|
_errorCarga = null;
|
||||||
|
notifyListeners();
|
||||||
|
try {
|
||||||
|
final results = await Future.wait([
|
||||||
|
radio.obtenerPopulares(limit: 30),
|
||||||
|
radio.obtenerTendencias(limit: 20),
|
||||||
|
]);
|
||||||
|
_populares = results[0];
|
||||||
|
_tendencias = results[1];
|
||||||
|
} catch (e) {
|
||||||
|
_errorCarga = 'Sin conexión a la API de radio';
|
||||||
|
} finally {
|
||||||
|
_cargandoPopulares = false;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> cargarFavoritos() async {
|
||||||
|
_listafavoritos = await favoritos.obtenerTodos();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> buscar({
|
||||||
|
String? nombre,
|
||||||
|
String? pais,
|
||||||
|
String? idioma,
|
||||||
|
String? tag,
|
||||||
|
}) async {
|
||||||
|
_cargandoBusqueda = true;
|
||||||
|
_resultadosBusqueda = [];
|
||||||
|
notifyListeners();
|
||||||
|
try {
|
||||||
|
_resultadosBusqueda = await radio.buscar(
|
||||||
|
nombre: nombre,
|
||||||
|
pais: pais,
|
||||||
|
idioma: idioma,
|
||||||
|
tag: tag,
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
// Error de búsqueda → toast, no bloquear pantalla
|
||||||
|
_errorController.add('Error en la búsqueda. Comprueba tu conexión.');
|
||||||
|
} finally {
|
||||||
|
_cargandoBusqueda = false;
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> reproducir(Emisora emisora) async {
|
||||||
|
try {
|
||||||
|
await audio.reproducir(emisora);
|
||||||
|
radio.registrarClick(emisora.uuid); // fire & forget
|
||||||
|
notifyListeners();
|
||||||
|
} catch (e) {
|
||||||
|
// Error de reproducción → SnackBar, no pintar en medio de la UI
|
||||||
|
_errorController.add('No se puede reproducir "${emisora.nombre}"');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> togglePlay() async {
|
||||||
|
await audio.togglePlay();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> toggleFavorito(Emisora emisora) async {
|
||||||
|
final esFav = await favoritos.toggleFavorito(emisora);
|
||||||
|
await cargarFavoritos();
|
||||||
|
return esFav;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> esFavorito(String uuid) => favoritos.esFavorito(uuid);
|
||||||
|
|
||||||
|
void iniciarTimer(int minutos) {
|
||||||
|
timer.iniciar(minutos);
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
void cancelarTimer() {
|
||||||
|
timer.cancelar();
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_errorController.close();
|
||||||
|
audio.dispose();
|
||||||
|
timer.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
134
lib/main.dart
@@ -1,122 +1,24 @@
|
|||||||
|
import 'package:audio_service/audio_service.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'app.dart';
|
||||||
|
import 'servicios/servicio_audio.dart';
|
||||||
|
|
||||||
void main() {
|
Future<void> main() async {
|
||||||
runApp(const MyApp());
|
WidgetsFlutterBinding.ensureInitialized();
|
||||||
}
|
|
||||||
|
|
||||||
class MyApp extends StatelessWidget {
|
// Inicializar audio_service para reproducción en background.
|
||||||
const MyApp({super.key});
|
// El handler se registra globalmente para que ServicioAudio lo use.
|
||||||
|
final handler = await AudioService.init(
|
||||||
// This widget is the root of your application.
|
builder: () => PluriWaveAudioHandler(),
|
||||||
@override
|
config: const AudioServiceConfig(
|
||||||
Widget build(BuildContext context) {
|
androidNotificationChannelId: 'es.freetimelab.pluriwave.audio',
|
||||||
return MaterialApp(
|
androidNotificationChannelName: 'PluriWave Radio',
|
||||||
title: 'Flutter Demo',
|
androidNotificationOngoing: true,
|
||||||
theme: ThemeData(
|
androidStopForegroundOnPause: true,
|
||||||
// This is the theme of your application.
|
notificationColor: Color(0xFF6750A4),
|
||||||
//
|
|
||||||
// TRY THIS: Try running your application with "flutter run". You'll see
|
|
||||||
// the application has a purple toolbar. Then, without quitting the app,
|
|
||||||
// try changing the seedColor in the colorScheme below to Colors.green
|
|
||||||
// and then invoke "hot reload" (save your changes or press the "hot
|
|
||||||
// reload" button in a Flutter-supported IDE, or press "r" if you used
|
|
||||||
// the command line to start the app).
|
|
||||||
//
|
|
||||||
// Notice that the counter didn't reset back to zero; the application
|
|
||||||
// state is not lost during the reload. To reset the state, use hot
|
|
||||||
// restart instead.
|
|
||||||
//
|
|
||||||
// This works for code too, not just values: Most code changes can be
|
|
||||||
// tested with just a hot reload.
|
|
||||||
colorScheme: .fromSeed(seedColor: Colors.deepPurple),
|
|
||||||
),
|
|
||||||
home: const MyHomePage(title: 'Flutter Demo Home Page'),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class MyHomePage extends StatefulWidget {
|
|
||||||
const MyHomePage({super.key, required this.title});
|
|
||||||
|
|
||||||
// This widget is the home page of your application. It is stateful, meaning
|
|
||||||
// that it has a State object (defined below) that contains fields that affect
|
|
||||||
// how it looks.
|
|
||||||
|
|
||||||
// This class is the configuration for the state. It holds the values (in this
|
|
||||||
// case the title) provided by the parent (in this case the App widget) and
|
|
||||||
// used by the build method of the State. Fields in a Widget subclass are
|
|
||||||
// always marked "final".
|
|
||||||
|
|
||||||
final String title;
|
|
||||||
|
|
||||||
@override
|
|
||||||
State<MyHomePage> createState() => _MyHomePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _MyHomePageState extends State<MyHomePage> {
|
|
||||||
int _counter = 0;
|
|
||||||
|
|
||||||
void _incrementCounter() {
|
|
||||||
setState(() {
|
|
||||||
// This call to setState tells the Flutter framework that something has
|
|
||||||
// changed in this State, which causes it to rerun the build method below
|
|
||||||
// so that the display can reflect the updated values. If we changed
|
|
||||||
// _counter without calling setState(), then the build method would not be
|
|
||||||
// called again, and so nothing would appear to happen.
|
|
||||||
_counter++;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
// This method is rerun every time setState is called, for instance as done
|
|
||||||
// by the _incrementCounter method above.
|
|
||||||
//
|
|
||||||
// The Flutter framework has been optimized to make rerunning build methods
|
|
||||||
// fast, so that you can just rebuild anything that needs updating rather
|
|
||||||
// than having to individually change instances of widgets.
|
|
||||||
return Scaffold(
|
|
||||||
appBar: AppBar(
|
|
||||||
// TRY THIS: Try changing the color here to a specific color (to
|
|
||||||
// Colors.amber, perhaps?) and trigger a hot reload to see the AppBar
|
|
||||||
// change color while the other colors stay the same.
|
|
||||||
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
|
|
||||||
// Here we take the value from the MyHomePage object that was created by
|
|
||||||
// the App.build method, and use it to set our appbar title.
|
|
||||||
title: Text(widget.title),
|
|
||||||
),
|
|
||||||
body: Center(
|
|
||||||
// Center is a layout widget. It takes a single child and positions it
|
|
||||||
// in the middle of the parent.
|
|
||||||
child: Column(
|
|
||||||
// Column is also a layout widget. It takes a list of children and
|
|
||||||
// arranges them vertically. By default, it sizes itself to fit its
|
|
||||||
// children horizontally, and tries to be as tall as its parent.
|
|
||||||
//
|
|
||||||
// Column has various properties to control how it sizes itself and
|
|
||||||
// how it positions its children. Here we use mainAxisAlignment to
|
|
||||||
// center the children vertically; the main axis here is the vertical
|
|
||||||
// axis because Columns are vertical (the cross axis would be
|
|
||||||
// horizontal).
|
|
||||||
//
|
|
||||||
// TRY THIS: Invoke "debug painting" (choose the "Toggle Debug Paint"
|
|
||||||
// action in the IDE, or press "p" in the console), to see the
|
|
||||||
// wireframe for each widget.
|
|
||||||
mainAxisAlignment: .center,
|
|
||||||
children: [
|
|
||||||
const Text('You have pushed the button this many times:'),
|
|
||||||
Text(
|
|
||||||
'$_counter',
|
|
||||||
style: Theme.of(context).textTheme.headlineMedium,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
floatingActionButton: FloatingActionButton(
|
|
||||||
onPressed: _incrementCounter,
|
|
||||||
tooltip: 'Increment',
|
|
||||||
child: const Icon(Icons.add),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
registrarHandler(handler);
|
||||||
|
|
||||||
|
runApp(const PluriWaveApp());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
/// Modelo de datos de una emisora de radio.
|
/// Modelo de datos de una emisora de radio.
|
||||||
///
|
///
|
||||||
/// Representa una emisora favorita almacenada en SQLite.
|
/// Unifica los campos de la Radio Browser API con los de la tabla SQLite
|
||||||
/// Los campos opcionales (favicon, pais, idioma, tags) pueden ser null
|
/// de favoritos. Los campos opcionales pueden ser null cuando la emisora
|
||||||
/// cuando la emisora no dispone de esa información.
|
/// no dispone de esa información.
|
||||||
class Emisora {
|
class Emisora {
|
||||||
final int? id;
|
final int? id;
|
||||||
final String uuid;
|
final String uuid;
|
||||||
@@ -10,8 +10,13 @@ class Emisora {
|
|||||||
final String url;
|
final String url;
|
||||||
final String? favicon;
|
final String? favicon;
|
||||||
final String? pais;
|
final String? pais;
|
||||||
|
final String? codigoPais; // ISO 3166-1 alpha-2
|
||||||
final String? idioma;
|
final String? idioma;
|
||||||
final String? tags;
|
final String? tags;
|
||||||
|
final String? codec;
|
||||||
|
final int? bitrate;
|
||||||
|
final int votes;
|
||||||
|
final int clickcount;
|
||||||
final int orden;
|
final int orden;
|
||||||
|
|
||||||
const Emisora({
|
const Emisora({
|
||||||
@@ -21,11 +26,34 @@ class Emisora {
|
|||||||
required this.url,
|
required this.url,
|
||||||
this.favicon,
|
this.favicon,
|
||||||
this.pais,
|
this.pais,
|
||||||
|
this.codigoPais,
|
||||||
this.idioma,
|
this.idioma,
|
||||||
this.tags,
|
this.tags,
|
||||||
|
this.codec,
|
||||||
|
this.bitrate,
|
||||||
|
this.votes = 0,
|
||||||
|
this.clickcount = 0,
|
||||||
this.orden = 0,
|
this.orden = 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
/// Construye una [Emisora] desde la respuesta JSON de Radio Browser API.
|
||||||
|
factory Emisora.fromApi(Map<String, dynamic> json) {
|
||||||
|
return Emisora(
|
||||||
|
uuid: json['stationuuid'] as String? ?? '',
|
||||||
|
nombre: json['name'] as String? ?? 'Sin nombre',
|
||||||
|
url: json['url_resolved'] as String? ?? json['url'] as String? ?? '',
|
||||||
|
favicon: _nonEmpty(json['favicon'] as String?),
|
||||||
|
pais: _nonEmpty(json['country'] as String?),
|
||||||
|
codigoPais: _nonEmpty(json['countrycode'] as String?),
|
||||||
|
idioma: _nonEmpty(json['language'] as String?),
|
||||||
|
tags: _nonEmpty(json['tags'] as String?),
|
||||||
|
codec: _nonEmpty(json['codec'] as String?),
|
||||||
|
bitrate: json['bitrate'] as int?,
|
||||||
|
votes: json['votes'] as int? ?? 0,
|
||||||
|
clickcount: json['clickcount'] as int? ?? 0,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/// Construye una [Emisora] desde una fila de la tabla `favoritos`.
|
/// Construye una [Emisora] desde una fila de la tabla `favoritos`.
|
||||||
factory Emisora.fromMap(Map<String, dynamic> map) {
|
factory Emisora.fromMap(Map<String, dynamic> map) {
|
||||||
return Emisora(
|
return Emisora(
|
||||||
@@ -35,14 +63,18 @@ class Emisora {
|
|||||||
url: map['url'] as String,
|
url: map['url'] as String,
|
||||||
favicon: map['favicon'] as String?,
|
favicon: map['favicon'] as String?,
|
||||||
pais: map['pais'] as String?,
|
pais: map['pais'] as String?,
|
||||||
|
codigoPais: map['codigo_pais'] as String?,
|
||||||
idioma: map['idioma'] as String?,
|
idioma: map['idioma'] as String?,
|
||||||
tags: map['tags'] as String?,
|
tags: map['tags'] as String?,
|
||||||
|
codec: map['codec'] as String?,
|
||||||
|
bitrate: map['bitrate'] as int?,
|
||||||
|
votes: map['votes'] as int? ?? 0,
|
||||||
|
clickcount: map['clickcount'] as int? ?? 0,
|
||||||
orden: map['orden'] as int? ?? 0,
|
orden: map['orden'] as int? ?? 0,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Serializa la emisora para inserción/actualización en SQLite.
|
/// Serializa para inserción/actualización en SQLite.
|
||||||
/// No incluye [id] — lo gestiona la BD.
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
'uuid': uuid,
|
'uuid': uuid,
|
||||||
@@ -50,13 +82,17 @@ class Emisora {
|
|||||||
'url': url,
|
'url': url,
|
||||||
'favicon': favicon,
|
'favicon': favicon,
|
||||||
'pais': pais,
|
'pais': pais,
|
||||||
|
'codigo_pais': codigoPais,
|
||||||
'idioma': idioma,
|
'idioma': idioma,
|
||||||
'tags': tags,
|
'tags': tags,
|
||||||
|
'codec': codec,
|
||||||
|
'bitrate': bitrate,
|
||||||
|
'votes': votes,
|
||||||
|
'clickcount': clickcount,
|
||||||
'orden': orden,
|
'orden': orden,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Devuelve una copia con los campos indicados modificados.
|
|
||||||
Emisora copyWith({
|
Emisora copyWith({
|
||||||
int? id,
|
int? id,
|
||||||
String? uuid,
|
String? uuid,
|
||||||
@@ -64,8 +100,13 @@ class Emisora {
|
|||||||
String? url,
|
String? url,
|
||||||
String? favicon,
|
String? favicon,
|
||||||
String? pais,
|
String? pais,
|
||||||
|
String? codigoPais,
|
||||||
String? idioma,
|
String? idioma,
|
||||||
String? tags,
|
String? tags,
|
||||||
|
String? codec,
|
||||||
|
int? bitrate,
|
||||||
|
int? votes,
|
||||||
|
int? clickcount,
|
||||||
int? orden,
|
int? orden,
|
||||||
}) {
|
}) {
|
||||||
return Emisora(
|
return Emisora(
|
||||||
@@ -75,22 +116,33 @@ class Emisora {
|
|||||||
url: url ?? this.url,
|
url: url ?? this.url,
|
||||||
favicon: favicon ?? this.favicon,
|
favicon: favicon ?? this.favicon,
|
||||||
pais: pais ?? this.pais,
|
pais: pais ?? this.pais,
|
||||||
|
codigoPais: codigoPais ?? this.codigoPais,
|
||||||
idioma: idioma ?? this.idioma,
|
idioma: idioma ?? this.idioma,
|
||||||
tags: tags ?? this.tags,
|
tags: tags ?? this.tags,
|
||||||
|
codec: codec ?? this.codec,
|
||||||
|
bitrate: bitrate ?? this.bitrate,
|
||||||
|
votes: votes ?? this.votes,
|
||||||
|
clickcount: clickcount ?? this.clickcount,
|
||||||
orden: orden ?? this.orden,
|
orden: orden ?? this.orden,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Lista de géneros/tags como lista limpia.
|
||||||
|
List<String> get generos {
|
||||||
|
if (tags == null || tags!.isEmpty) return [];
|
||||||
|
return tags!.split(',').map((t) => t.trim()).where((t) => t.isNotEmpty).toList();
|
||||||
|
}
|
||||||
|
|
||||||
|
static String? _nonEmpty(String? s) =>
|
||||||
|
(s == null || s.trim().isEmpty) ? null : s.trim();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() =>
|
String toString() => 'Emisora(uuid: $uuid, nombre: $nombre)';
|
||||||
'Emisora(id: $id, uuid: $uuid, nombre: $nombre, orden: $orden)';
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(Object other) =>
|
bool operator ==(Object other) =>
|
||||||
identical(this, other) ||
|
identical(this, other) ||
|
||||||
other is Emisora &&
|
other is Emisora && runtimeType == other.runtimeType && uuid == other.uuid;
|
||||||
runtimeType == other.runtimeType &&
|
|
||||||
uuid == other.uuid;
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
int get hashCode => uuid.hashCode;
|
int get hashCode => uuid.hashCode;
|
||||||
|
|||||||
84
lib/pantallas/pantalla_ajustes.dart
Normal file
@@ -0,0 +1,84 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../estado/estado_radio.dart';
|
||||||
|
|
||||||
|
/// Pantalla de ajustes — por ahora muestra info de la app.
|
||||||
|
/// En Fase 3 se añadirá Export/Import config y gestión PRO.
|
||||||
|
class PantallaAjustes extends StatelessWidget {
|
||||||
|
const PantallaAjustes({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final estado = context.read<EstadoRadio>();
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
appBar: AppBar(title: const Text('Ajustes')),
|
||||||
|
body: ListView(
|
||||||
|
children: [
|
||||||
|
// Info app
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.info_outline),
|
||||||
|
title: const Text('PluriWave'),
|
||||||
|
subtitle: const Text('v0.3.0 — Radio mundial'),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
// Favoritos
|
||||||
|
FutureBuilder<int>(
|
||||||
|
future: estado.favoritos.obtenerTodos().then((l) => l.length),
|
||||||
|
builder: (ctx, snap) => ListTile(
|
||||||
|
leading: const Icon(Icons.favorite_outline),
|
||||||
|
title: const Text('Favoritos guardados'),
|
||||||
|
trailing: Text(
|
||||||
|
snap.data?.toString() ?? '—',
|
||||||
|
style: theme.textTheme.bodyLarge,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
// Filtro emisoras
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.verified_outlined),
|
||||||
|
title: const Text('Filtro de emisoras'),
|
||||||
|
subtitle: const Text('Solo emisoras verificadas como activas'),
|
||||||
|
trailing: const Icon(Icons.check_circle, color: Colors.green),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.music_off_outlined),
|
||||||
|
title: const Text('Audio en background'),
|
||||||
|
subtitle: const Text('Activo — continúa al apagar pantalla'),
|
||||||
|
trailing: const Icon(Icons.check_circle, color: Colors.green),
|
||||||
|
),
|
||||||
|
const Divider(),
|
||||||
|
// Próximamente
|
||||||
|
const Padding(
|
||||||
|
padding: EdgeInsets.fromLTRB(16, 12, 16, 4),
|
||||||
|
child: Text('PRÓXIMAMENTE', style: TextStyle(fontSize: 12, letterSpacing: 1.2)),
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.upload_outlined),
|
||||||
|
title: const Text('Exportar configuración'),
|
||||||
|
subtitle: const Text('Favoritos, radios custom, presets EQ'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.download_outlined),
|
||||||
|
title: const Text('Importar configuración'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.add_circle_outline),
|
||||||
|
title: const Text('Añadir radio personalizada'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
ListTile(
|
||||||
|
leading: const Icon(Icons.equalizer_outlined),
|
||||||
|
title: const Text('Ecualizador'),
|
||||||
|
subtitle: const Text('5 bandas, presets por emisora'),
|
||||||
|
enabled: false,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
180
lib/pantallas/pantalla_buscar.dart
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../estado/estado_radio.dart';
|
||||||
|
import '../widgets/tarjeta_emisora.dart';
|
||||||
|
|
||||||
|
const _paises = [
|
||||||
|
('España', 'ES'), ('USA', 'US'), ('México', 'MX'), ('Argentina', 'AR'),
|
||||||
|
('UK', 'GB'), ('Francia', 'FR'), ('Alemania', 'DE'), ('Italia', 'IT'),
|
||||||
|
('Brasil', 'BR'), ('Japón', 'JP'),
|
||||||
|
];
|
||||||
|
|
||||||
|
const _idiomas = [
|
||||||
|
'spanish', 'english', 'french', 'german', 'portuguese',
|
||||||
|
'italian', 'japanese', 'arabic', 'russian',
|
||||||
|
];
|
||||||
|
|
||||||
|
/// Pantalla de búsqueda avanzada de emisoras.
|
||||||
|
class PantallaBuscar extends StatefulWidget {
|
||||||
|
const PantallaBuscar({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PantallaBuscar> createState() => _PantallaBuscarState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PantallaBuscarState extends State<PantallaBuscar> {
|
||||||
|
final _controller = TextEditingController();
|
||||||
|
String? _paisSeleccionado;
|
||||||
|
String? _idiomaSeleccionado;
|
||||||
|
bool _buscando = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_controller.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _buscar() {
|
||||||
|
final q = _controller.text.trim();
|
||||||
|
context.read<EstadoRadio>().buscar(
|
||||||
|
nombre: q.isNotEmpty ? q : null,
|
||||||
|
pais: _paisSeleccionado,
|
||||||
|
idioma: _idiomaSeleccionado,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final estado = context.watch<EstadoRadio>();
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return Column(
|
||||||
|
children: [
|
||||||
|
// Barra de búsqueda
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||||
|
child: SearchBar(
|
||||||
|
controller: _controller,
|
||||||
|
hintText: 'Nombre de la emisora...',
|
||||||
|
leading: const Icon(Icons.search),
|
||||||
|
trailing: [
|
||||||
|
if (_controller.text.isNotEmpty)
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.clear),
|
||||||
|
onPressed: () {
|
||||||
|
_controller.clear();
|
||||||
|
setState(() {});
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
onSubmitted: (_) => _buscar(),
|
||||||
|
onChanged: (_) => setState(() {}),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
// Filtros país
|
||||||
|
_seccionFiltro(
|
||||||
|
theme,
|
||||||
|
'País',
|
||||||
|
_paises.map((p) => (p.$1, p.$2)).toList(),
|
||||||
|
_paisSeleccionado,
|
||||||
|
(v) => setState(() {
|
||||||
|
_paisSeleccionado = v;
|
||||||
|
_buscar();
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
// Filtros idioma
|
||||||
|
_seccionFiltro(
|
||||||
|
theme,
|
||||||
|
'Idioma',
|
||||||
|
_idiomas.map((i) => (i, i)).toList(),
|
||||||
|
_idiomaSeleccionado,
|
||||||
|
(v) => setState(() {
|
||||||
|
_idiomaSeleccionado = v;
|
||||||
|
_buscar();
|
||||||
|
}),
|
||||||
|
),
|
||||||
|
// Resultados
|
||||||
|
Expanded(
|
||||||
|
child: _resultados(estado, theme),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _seccionFiltro(
|
||||||
|
ThemeData theme,
|
||||||
|
String titulo,
|
||||||
|
List<(String, String)> opciones,
|
||||||
|
String? seleccionado,
|
||||||
|
void Function(String?) onChanged,
|
||||||
|
) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text(titulo, style: theme.textTheme.labelLarge),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
SizedBox(
|
||||||
|
height: 36,
|
||||||
|
child: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: opciones.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 6),
|
||||||
|
itemBuilder: (_, i) {
|
||||||
|
final (label, value) = opciones[i];
|
||||||
|
final sel = seleccionado == value;
|
||||||
|
return FilterChip(
|
||||||
|
label: Text(label),
|
||||||
|
selected: sel,
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
onSelected: (_) => onChanged(sel ? null : value),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _resultados(EstadoRadio estado, ThemeData theme) {
|
||||||
|
if (estado.cargandoBusqueda) {
|
||||||
|
return const Center(child: CircularProgressIndicator());
|
||||||
|
}
|
||||||
|
|
||||||
|
final resultados = estado.resultadosBusqueda;
|
||||||
|
|
||||||
|
if (resultados.isEmpty) {
|
||||||
|
final sinFiltros = _controller.text.isEmpty &&
|
||||||
|
_paisSeleccionado == null &&
|
||||||
|
_idiomaSeleccionado == null;
|
||||||
|
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.search, size: 64, color: theme.colorScheme.outlineVariant),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text(
|
||||||
|
sinFiltros ? 'Busca una emisora' : 'Sin resultados',
|
||||||
|
style: theme.textTheme.titleMedium,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ListView.separated(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
itemCount: resultados.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(height: 4),
|
||||||
|
itemBuilder: (context, i) => TarjetaEmisora(
|
||||||
|
emisora: resultados[i],
|
||||||
|
esCompacta: true,
|
||||||
|
onTap: () => context.read<EstadoRadio>().reproducir(resultados[i]),
|
||||||
|
).animate().fadeIn(delay: (i * 20).ms),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
75
lib/pantallas/pantalla_favoritos.dart
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import '../estado/estado_radio.dart';
|
||||||
|
import '../widgets/tarjeta_emisora.dart';
|
||||||
|
|
||||||
|
/// Pantalla de emisoras favoritas con reordenado y swipe-to-delete.
|
||||||
|
class PantallaFavoritos extends StatelessWidget {
|
||||||
|
const PantallaFavoritos({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final estado = context.watch<EstadoRadio>();
|
||||||
|
final favoritos = estado.listaFavoritos;
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
if (favoritos.isEmpty) {
|
||||||
|
return Center(
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.favorite_border, size: 72, color: theme.colorScheme.outlineVariant),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Text('Sin favoritos aún', style: theme.textTheme.titleMedium),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Text(
|
||||||
|
'Toca ♥ en cualquier emisora para guardarla',
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ReorderableListView.builder(
|
||||||
|
padding: const EdgeInsets.all(8),
|
||||||
|
onReorder: (oldIndex, newIndex) async {
|
||||||
|
if (newIndex > oldIndex) newIndex--;
|
||||||
|
final emisora = favoritos[oldIndex];
|
||||||
|
await estado.favoritos.reordenar(emisora.uuid, newIndex);
|
||||||
|
await estado.cargarFavoritos();
|
||||||
|
},
|
||||||
|
itemCount: favoritos.length,
|
||||||
|
itemBuilder: (context, i) {
|
||||||
|
final emisora = favoritos[i];
|
||||||
|
return Dismissible(
|
||||||
|
key: Key(emisora.uuid),
|
||||||
|
direction: DismissDirection.endToStart,
|
||||||
|
background: Container(
|
||||||
|
color: theme.colorScheme.error,
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
padding: const EdgeInsets.only(right: 16),
|
||||||
|
child: Icon(Icons.delete, color: theme.colorScheme.onError),
|
||||||
|
),
|
||||||
|
onDismissed: (_) async {
|
||||||
|
await estado.favoritos.eliminar(emisora.uuid);
|
||||||
|
await estado.cargarFavoritos();
|
||||||
|
if (context.mounted) {
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('${emisora.nombre} eliminada de favoritos')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: TarjetaEmisora(
|
||||||
|
key: Key(emisora.uuid),
|
||||||
|
emisora: emisora,
|
||||||
|
esCompacta: true,
|
||||||
|
onTap: () => estado.reproducir(emisora),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
214
lib/pantallas/pantalla_inicio.dart
Normal file
@@ -0,0 +1,214 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shimmer/shimmer.dart' as shimmer;
|
||||||
|
import '../estado/estado_radio.dart';
|
||||||
|
import '../widgets/tarjeta_emisora.dart';
|
||||||
|
|
||||||
|
/// Pantalla principal: emisoras populares y por género.
|
||||||
|
class PantallaInicio extends StatefulWidget {
|
||||||
|
const PantallaInicio({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PantallaInicio> createState() => _PantallaInicioState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PantallaInicioState extends State<PantallaInicio> {
|
||||||
|
static const _generos = [
|
||||||
|
'pop', 'rock', 'jazz', 'classical', 'electronic', 'news',
|
||||||
|
'talk', 'hip-hop', 'country', 'metal', 'reggae', 'latin',
|
||||||
|
];
|
||||||
|
String? _generoSeleccionado;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final estado = context.watch<EstadoRadio>();
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return RefreshIndicator(
|
||||||
|
onRefresh: estado.cargarPopulares,
|
||||||
|
child: CustomScrollView(
|
||||||
|
slivers: [
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: _seccionTendencias(estado, theme),
|
||||||
|
),
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: _chipGeneros(theme),
|
||||||
|
),
|
||||||
|
if (estado.error != null)
|
||||||
|
SliverToBoxAdapter(
|
||||||
|
child: _errorBanner(estado, theme),
|
||||||
|
),
|
||||||
|
_gridEmisoras(estado, theme),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _seccionTendencias(EstadoRadio estado, ThemeData theme) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 0),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('🔥 Tendencias', style: theme.textTheme.titleMedium),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
SizedBox(
|
||||||
|
height: 56,
|
||||||
|
child: estado.cargandoPopulares
|
||||||
|
? ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: 5,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 8),
|
||||||
|
itemBuilder: (_, __) => _ChipShimmer(theme: theme),
|
||||||
|
)
|
||||||
|
: ListView.separated(
|
||||||
|
scrollDirection: Axis.horizontal,
|
||||||
|
itemCount: estado.tendencias.length,
|
||||||
|
separatorBuilder: (_, __) => const SizedBox(width: 8),
|
||||||
|
itemBuilder: (context, i) {
|
||||||
|
final e = estado.tendencias[i];
|
||||||
|
return ActionChip(
|
||||||
|
avatar: const Icon(Icons.radio, size: 18),
|
||||||
|
label: Text(e.nombre, maxLines: 1),
|
||||||
|
onPressed: () => context.read<EstadoRadio>().reproducir(e),
|
||||||
|
).animate().fadeIn(delay: (i * 50).ms);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _chipGeneros(ThemeData theme) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('Géneros', style: theme.textTheme.titleMedium),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
runSpacing: 4,
|
||||||
|
children: _generos.map((g) {
|
||||||
|
final seleccionado = _generoSeleccionado == g;
|
||||||
|
return FilterChip(
|
||||||
|
label: Text(g),
|
||||||
|
selected: seleccionado,
|
||||||
|
onSelected: (_) {
|
||||||
|
setState(() {
|
||||||
|
_generoSeleccionado = seleccionado ? null : g;
|
||||||
|
});
|
||||||
|
if (!seleccionado) {
|
||||||
|
context.read<EstadoRadio>().buscar(tag: g);
|
||||||
|
} else {
|
||||||
|
context.read<EstadoRadio>().cargarPopulares();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}).toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _errorBanner(EstadoRadio estado, ThemeData theme) {
|
||||||
|
return Padding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
child: Card(
|
||||||
|
color: theme.colorScheme.errorContainer,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(12),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Icon(Icons.wifi_off, color: theme.colorScheme.onErrorContainer),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
Expanded(
|
||||||
|
child: Text(
|
||||||
|
estado.error!,
|
||||||
|
style: TextStyle(color: theme.colorScheme.onErrorContainer),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
TextButton(
|
||||||
|
onPressed: estado.cargarPopulares,
|
||||||
|
child: const Text('Reintentar'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _gridEmisoras(EstadoRadio estado, ThemeData theme) {
|
||||||
|
final emisoras = _generoSeleccionado != null
|
||||||
|
? estado.resultadosBusqueda
|
||||||
|
: estado.populares;
|
||||||
|
final cargando = estado.cargandoPopulares ||
|
||||||
|
(_generoSeleccionado != null && estado.cargandoBusqueda);
|
||||||
|
|
||||||
|
if (cargando) {
|
||||||
|
return SliverGrid(
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(_, __) => const TarjetaEmisoraShimmer(),
|
||||||
|
childCount: 12,
|
||||||
|
),
|
||||||
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: 2,
|
||||||
|
childAspectRatio: 0.85,
|
||||||
|
crossAxisSpacing: 8,
|
||||||
|
mainAxisSpacing: 8,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (emisoras.isEmpty) {
|
||||||
|
return const SliverFillRemaining(
|
||||||
|
child: Center(child: Text('No hay emisoras disponibles')),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SliverPadding(
|
||||||
|
padding: const EdgeInsets.all(16),
|
||||||
|
sliver: SliverGrid(
|
||||||
|
delegate: SliverChildBuilderDelegate(
|
||||||
|
(context, i) => TarjetaEmisora(
|
||||||
|
emisora: emisoras[i],
|
||||||
|
onTap: () => context.read<EstadoRadio>().reproducir(emisoras[i]),
|
||||||
|
).animate().fadeIn(delay: (i * 30).ms).slideY(begin: 0.1),
|
||||||
|
childCount: emisoras.length,
|
||||||
|
),
|
||||||
|
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||||
|
crossAxisCount: 2,
|
||||||
|
childAspectRatio: 0.85,
|
||||||
|
crossAxisSpacing: 8,
|
||||||
|
mainAxisSpacing: 8,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class _ChipShimmer extends StatelessWidget {
|
||||||
|
final ThemeData theme;
|
||||||
|
const _ChipShimmer({required this.theme});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return shimmer.Shimmer.fromColors(
|
||||||
|
baseColor: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
highlightColor: theme.colorScheme.surface,
|
||||||
|
child: Container(
|
||||||
|
width: 120,
|
||||||
|
height: 56,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
472
lib/pantallas/pantalla_reproductor.dart
Normal file
@@ -0,0 +1,472 @@
|
|||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_animate/flutter_animate.dart';
|
||||||
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:shimmer/shimmer.dart';
|
||||||
|
import '../estado/estado_radio.dart';
|
||||||
|
import '../modelos/emisora.dart';
|
||||||
|
import '../servicios/servicio_audio.dart';
|
||||||
|
import '../servicios/servicio_timer.dart';
|
||||||
|
|
||||||
|
/// Pantalla completa del reproductor de radio.
|
||||||
|
///
|
||||||
|
/// Muestra: carátula/logo grande, nombre emisora, información (país, idioma,
|
||||||
|
/// codec/bitrate), controles play/pause, botón favorito, acceso al timer.
|
||||||
|
///
|
||||||
|
/// Se abre como ruta desde cualquier pantalla al pulsar sobre una emisora
|
||||||
|
/// o desde el MiniReproductor.
|
||||||
|
class PantallaReproductor extends StatefulWidget {
|
||||||
|
final Emisora emisora;
|
||||||
|
|
||||||
|
const PantallaReproductor({super.key, required this.emisora});
|
||||||
|
|
||||||
|
/// Navega a la pantalla del reproductor.
|
||||||
|
static Future<void> abrir(BuildContext context, Emisora emisora) {
|
||||||
|
return Navigator.push(
|
||||||
|
context,
|
||||||
|
PageRouteBuilder(
|
||||||
|
pageBuilder: (_, animation, __) => PantallaReproductor(emisora: emisora),
|
||||||
|
transitionsBuilder: (_, animation, __, child) => SlideTransition(
|
||||||
|
position: Tween<Offset>(
|
||||||
|
begin: const Offset(0, 1),
|
||||||
|
end: Offset.zero,
|
||||||
|
).animate(CurvedAnimation(parent: animation, curve: Curves.easeOutCubic)),
|
||||||
|
child: child,
|
||||||
|
),
|
||||||
|
transitionDuration: const Duration(milliseconds: 350),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<PantallaReproductor> createState() => _PantallaReproductorState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _PantallaReproductorState extends State<PantallaReproductor>
|
||||||
|
with SingleTickerProviderStateMixin {
|
||||||
|
late AnimationController _pulseController;
|
||||||
|
bool _esFavorito = false;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
_pulseController = AnimationController(
|
||||||
|
vsync: this,
|
||||||
|
duration: const Duration(seconds: 2),
|
||||||
|
);
|
||||||
|
_checkFavorito();
|
||||||
|
_iniciarReproduccion();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _checkFavorito() async {
|
||||||
|
final estado = context.read<EstadoRadio>();
|
||||||
|
final fav = await estado.esFavorito(widget.emisora.uuid);
|
||||||
|
if (mounted) setState(() => _esFavorito = fav);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> _iniciarReproduccion() async {
|
||||||
|
final estado = context.read<EstadoRadio>();
|
||||||
|
// Solo reproductor si no es ya la emisora activa
|
||||||
|
if (estado.emisoraActual?.uuid != widget.emisora.uuid) {
|
||||||
|
await estado.reproducir(widget.emisora);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
_pulseController.dispose();
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final estado = context.watch<EstadoRadio>();
|
||||||
|
|
||||||
|
return Scaffold(
|
||||||
|
backgroundColor: theme.colorScheme.surface,
|
||||||
|
appBar: AppBar(
|
||||||
|
backgroundColor: Colors.transparent,
|
||||||
|
elevation: 0,
|
||||||
|
leading: IconButton(
|
||||||
|
icon: const Icon(Icons.keyboard_arrow_down_rounded, size: 32),
|
||||||
|
tooltip: 'Cerrar',
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
// Botón favorito
|
||||||
|
IconButton(
|
||||||
|
icon: Icon(
|
||||||
|
_esFavorito ? Icons.favorite_rounded : Icons.favorite_outline_rounded,
|
||||||
|
color: _esFavorito ? theme.colorScheme.error : null,
|
||||||
|
),
|
||||||
|
tooltip: _esFavorito ? 'Quitar de favoritos' : 'Añadir a favoritos',
|
||||||
|
onPressed: () async {
|
||||||
|
final esFav = await estado.toggleFavorito(widget.emisora);
|
||||||
|
if (mounted) setState(() => _esFavorito = esFav);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
body: SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 32),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
const Spacer(flex: 1),
|
||||||
|
// Carátula / logo grande
|
||||||
|
_Artwork(
|
||||||
|
emisora: widget.emisora,
|
||||||
|
estadoStream: estado.estadoStream,
|
||||||
|
).animate().scale(begin: const Offset(0.8, 0.8), duration: 400.ms,
|
||||||
|
curve: Curves.easeOutBack),
|
||||||
|
const SizedBox(height: 32),
|
||||||
|
// Nombre de la emisora
|
||||||
|
Text(
|
||||||
|
widget.emisora.nombre,
|
||||||
|
style: theme.textTheme.headlineSmall?.copyWith(
|
||||||
|
fontWeight: FontWeight.bold,
|
||||||
|
),
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
maxLines: 2,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
).animate().fadeIn(delay: 150.ms),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
// Info: país, idioma
|
||||||
|
_InfoChips(emisora: widget.emisora)
|
||||||
|
.animate()
|
||||||
|
.fadeIn(delay: 200.ms)
|
||||||
|
.slideY(begin: 0.2),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
// Codec / bitrate
|
||||||
|
if (widget.emisora.codec != null || widget.emisora.bitrate != null)
|
||||||
|
Text(
|
||||||
|
_codecInfo(widget.emisora),
|
||||||
|
style: theme.textTheme.bodySmall?.copyWith(
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
).animate().fadeIn(delay: 250.ms),
|
||||||
|
const Spacer(flex: 2),
|
||||||
|
// Controles
|
||||||
|
_Controles(
|
||||||
|
estado: estado,
|
||||||
|
emisora: widget.emisora,
|
||||||
|
).animate().fadeIn(delay: 300.ms).slideY(begin: 0.3),
|
||||||
|
const SizedBox(height: 24),
|
||||||
|
// Timer
|
||||||
|
_TimerWidget(estado: estado)
|
||||||
|
.animate()
|
||||||
|
.fadeIn(delay: 400.ms),
|
||||||
|
const Spacer(flex: 1),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
String _codecInfo(Emisora e) {
|
||||||
|
final parts = <String>[];
|
||||||
|
if (e.codec != null) parts.add(e.codec!.toUpperCase());
|
||||||
|
if (e.bitrate != null && e.bitrate! > 0) parts.add('${e.bitrate} kbps');
|
||||||
|
return parts.join(' · ');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Artwork ────────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _Artwork extends StatelessWidget {
|
||||||
|
final Emisora emisora;
|
||||||
|
final Stream<EstadoReproduccion> estadoStream;
|
||||||
|
|
||||||
|
const _Artwork({required this.emisora, required this.estadoStream});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final size = MediaQuery.of(context).size.width * 0.65;
|
||||||
|
|
||||||
|
return StreamBuilder<EstadoReproduccion>(
|
||||||
|
stream: estadoStream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final reproduciendo = snapshot.data == EstadoReproduccion.reproduciendo;
|
||||||
|
final cargando = snapshot.data == EstadoReproduccion.cargando;
|
||||||
|
|
||||||
|
return AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 300),
|
||||||
|
width: size,
|
||||||
|
height: size,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
boxShadow: reproduciendo
|
||||||
|
? [
|
||||||
|
BoxShadow(
|
||||||
|
color: theme.colorScheme.primary.withValues(alpha: 0.4),
|
||||||
|
blurRadius: 30,
|
||||||
|
spreadRadius: 5,
|
||||||
|
),
|
||||||
|
]
|
||||||
|
: [
|
||||||
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: 0.2),
|
||||||
|
blurRadius: 12,
|
||||||
|
spreadRadius: 2,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(20),
|
||||||
|
child: Stack(
|
||||||
|
fit: StackFit.expand,
|
||||||
|
children: [
|
||||||
|
// Logo / imagen
|
||||||
|
if (emisora.favicon != null && emisora.favicon!.isNotEmpty)
|
||||||
|
CachedNetworkImage(
|
||||||
|
imageUrl: emisora.favicon!,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (_, __) => _shimmer(theme),
|
||||||
|
errorWidget: (_, __, ___) => _iconoFallback(theme),
|
||||||
|
)
|
||||||
|
else
|
||||||
|
_iconoFallback(theme),
|
||||||
|
// Overlay de carga
|
||||||
|
if (cargando)
|
||||||
|
Container(
|
||||||
|
color: Colors.black45,
|
||||||
|
child: const Center(
|
||||||
|
child: CircularProgressIndicator(color: Colors.white),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _shimmer(ThemeData theme) => Shimmer.fromColors(
|
||||||
|
baseColor: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
highlightColor: theme.colorScheme.surface,
|
||||||
|
child: Container(color: theme.colorScheme.surfaceContainerHighest),
|
||||||
|
);
|
||||||
|
|
||||||
|
Widget _iconoFallback(ThemeData theme) => Container(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
child: Icon(
|
||||||
|
Icons.radio_rounded,
|
||||||
|
size: 80,
|
||||||
|
color: theme.colorScheme.onPrimaryContainer,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Info chips ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _InfoChips extends StatelessWidget {
|
||||||
|
final Emisora emisora;
|
||||||
|
const _InfoChips({required this.emisora});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
final items = <String>[];
|
||||||
|
if (emisora.pais != null) items.add(emisora.pais!);
|
||||||
|
if (emisora.idioma != null) items.add(emisora.idioma!);
|
||||||
|
if (items.isEmpty) return const SizedBox.shrink();
|
||||||
|
|
||||||
|
return Wrap(
|
||||||
|
spacing: 6,
|
||||||
|
children: items
|
||||||
|
.map((label) => Chip(
|
||||||
|
label: Text(label),
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
backgroundColor: theme.colorScheme.secondaryContainer,
|
||||||
|
labelStyle: TextStyle(
|
||||||
|
color: theme.colorScheme.onSecondaryContainer,
|
||||||
|
fontSize: 12),
|
||||||
|
padding: EdgeInsets.zero,
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Controles ──────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _Controles extends StatelessWidget {
|
||||||
|
final EstadoRadio estado;
|
||||||
|
final Emisora emisora;
|
||||||
|
|
||||||
|
const _Controles({required this.estado, required this.emisora});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
return StreamBuilder<EstadoReproduccion>(
|
||||||
|
stream: estado.estadoStream,
|
||||||
|
builder: (context, snapshot) {
|
||||||
|
final s = snapshot.data ?? EstadoReproduccion.detenido;
|
||||||
|
final reproduciendo = s == EstadoReproduccion.reproduciendo;
|
||||||
|
final cargando = s == EstadoReproduccion.cargando;
|
||||||
|
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
// Botón detener
|
||||||
|
IconButton(
|
||||||
|
icon: const Icon(Icons.stop_rounded),
|
||||||
|
iconSize: 36,
|
||||||
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
|
tooltip: 'Detener',
|
||||||
|
onPressed: cargando ? null : () => estado.audio.detener(),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
// Botón play/pause principal
|
||||||
|
AnimatedContainer(
|
||||||
|
duration: const Duration(milliseconds: 200),
|
||||||
|
width: 72,
|
||||||
|
height: 72,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
color: theme.colorScheme.primary,
|
||||||
|
boxShadow: [
|
||||||
|
BoxShadow(
|
||||||
|
color: theme.colorScheme.primary.withValues(alpha: 0.35),
|
||||||
|
blurRadius: reproduciendo ? 16 : 6,
|
||||||
|
spreadRadius: reproduciendo ? 4 : 0,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
child: Material(
|
||||||
|
color: Colors.transparent,
|
||||||
|
shape: const CircleBorder(),
|
||||||
|
child: InkWell(
|
||||||
|
customBorder: const CircleBorder(),
|
||||||
|
onTap: cargando
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
|
if (reproduciendo || s == EstadoReproduccion.pausado) {
|
||||||
|
estado.togglePlay();
|
||||||
|
} else {
|
||||||
|
estado.reproducir(emisora);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: Center(
|
||||||
|
child: cargando
|
||||||
|
? const SizedBox(
|
||||||
|
width: 28,
|
||||||
|
height: 28,
|
||||||
|
child: CircularProgressIndicator(
|
||||||
|
strokeWidth: 2.5,
|
||||||
|
color: Colors.white,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
: Icon(
|
||||||
|
reproduciendo
|
||||||
|
? Icons.pause_rounded
|
||||||
|
: Icons.play_arrow_rounded,
|
||||||
|
size: 40,
|
||||||
|
color: theme.colorScheme.onPrimary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 16),
|
||||||
|
// Indicador en vivo
|
||||||
|
Icon(
|
||||||
|
Icons.fiber_manual_record_rounded,
|
||||||
|
size: 36,
|
||||||
|
color: reproduciendo
|
||||||
|
? theme.colorScheme.error
|
||||||
|
: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─── Timer widget ────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
class _TimerWidget extends StatelessWidget {
|
||||||
|
final EstadoRadio estado;
|
||||||
|
const _TimerWidget({required this.estado});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
|
||||||
|
if (!estado.timer.activo) {
|
||||||
|
return TextButton.icon(
|
||||||
|
icon: const Icon(Icons.bedtime_outlined, size: 18),
|
||||||
|
label: const Text('Timer de sueño'),
|
||||||
|
onPressed: () => _mostrarTimerDialog(context),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return StreamBuilder<Duration>(
|
||||||
|
stream: estado.timer.tiempoRestanteStream,
|
||||||
|
builder: (context, snap) {
|
||||||
|
final t = snap.data ?? Duration.zero;
|
||||||
|
final m = t.inMinutes.remainder(60).toString().padLeft(2, '0');
|
||||||
|
final s = t.inSeconds.remainder(60).toString().padLeft(2, '0');
|
||||||
|
final label = t.inHours > 0
|
||||||
|
? '${t.inHours}h ${m}m'
|
||||||
|
: '${m}m ${s}s';
|
||||||
|
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Icon(Icons.bedtime_rounded, size: 16, color: theme.colorScheme.primary),
|
||||||
|
const SizedBox(width: 6),
|
||||||
|
Text(label, style: theme.textTheme.bodyMedium),
|
||||||
|
const SizedBox(width: 8),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => estado.cancelarTimer(),
|
||||||
|
style: TextButton.styleFrom(
|
||||||
|
visualDensity: VisualDensity.compact,
|
||||||
|
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
|
||||||
|
),
|
||||||
|
child: const Text('Cancelar'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _mostrarTimerDialog(BuildContext context) {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => SafeArea(
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
child: Column(
|
||||||
|
mainAxisSize: MainAxisSize.min,
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Text('Timer de sueño', style: Theme.of(ctx).textTheme.titleLarge),
|
||||||
|
const SizedBox(height: 16),
|
||||||
|
Wrap(
|
||||||
|
spacing: 8,
|
||||||
|
children: opcionesTimer
|
||||||
|
.map((min) => ActionChip(
|
||||||
|
label: Text('$min min'),
|
||||||
|
onPressed: () {
|
||||||
|
estado.iniciarTimer(min);
|
||||||
|
Navigator.pop(ctx);
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
194
lib/servicios/servicio_audio.dart
Normal file
@@ -0,0 +1,194 @@
|
|||||||
|
import 'package:audio_service/audio_service.dart';
|
||||||
|
import 'package:just_audio/just_audio.dart';
|
||||||
|
import '../modelos/emisora.dart';
|
||||||
|
|
||||||
|
/// Estado de reproducción expuesto al UI.
|
||||||
|
enum EstadoReproduccion { detenido, cargando, reproduciendo, pausado, error }
|
||||||
|
|
||||||
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
// Handler global — inicializado en main.dart con AudioService.init
|
||||||
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
PluriWaveAudioHandler? _handlerGlobal;
|
||||||
|
|
||||||
|
/// Registra el handler. Llamar desde main.dart tras AudioService.init.
|
||||||
|
void registrarHandler(PluriWaveAudioHandler handler) {
|
||||||
|
_handlerGlobal = handler;
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Wrapper de alto nivel para el UI.
|
||||||
|
///
|
||||||
|
/// Delega TODA la reproducción al [PluriWaveAudioHandler] para garantizar
|
||||||
|
/// que el audio siga vivo en background con notificación foreground.
|
||||||
|
class ServicioAudio {
|
||||||
|
PluriWaveAudioHandler get _handler {
|
||||||
|
assert(_handlerGlobal != null,
|
||||||
|
'ServicioAudio: handler no registrado. '
|
||||||
|
'Llama registrarHandler() en main.dart tras AudioService.init.');
|
||||||
|
return _handlerGlobal!;
|
||||||
|
}
|
||||||
|
|
||||||
|
Emisora? get emisoraActual => _handler.emisoraActual;
|
||||||
|
|
||||||
|
Stream<EstadoReproduccion> get estadoStream =>
|
||||||
|
_handler.playbackState.map((s) {
|
||||||
|
if (s.processingState == AudioProcessingState.loading ||
|
||||||
|
s.processingState == AudioProcessingState.buffering) {
|
||||||
|
return EstadoReproduccion.cargando;
|
||||||
|
}
|
||||||
|
if (s.playing) return EstadoReproduccion.reproduciendo;
|
||||||
|
if (s.processingState == AudioProcessingState.idle) {
|
||||||
|
return EstadoReproduccion.detenido;
|
||||||
|
}
|
||||||
|
return EstadoReproduccion.pausado;
|
||||||
|
});
|
||||||
|
|
||||||
|
Future<void> reproducir(Emisora emisora) async {
|
||||||
|
final item = MediaItem(
|
||||||
|
id: emisora.url,
|
||||||
|
title: emisora.nombre,
|
||||||
|
artist: emisora.pais ?? '',
|
||||||
|
album: 'PluriWave',
|
||||||
|
artUri: emisora.favicon != null && emisora.favicon!.isNotEmpty
|
||||||
|
? Uri.tryParse(emisora.favicon!)
|
||||||
|
: null,
|
||||||
|
extras: {'uuid': emisora.uuid},
|
||||||
|
);
|
||||||
|
await _handler.playMediaItem(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> pausar() => _handler.pause();
|
||||||
|
Future<void> reanudar() => _handler.play();
|
||||||
|
|
||||||
|
Future<void> togglePlay() async {
|
||||||
|
if (_handler.playbackState.value.playing) {
|
||||||
|
await pausar();
|
||||||
|
} else {
|
||||||
|
await reanudar();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> detener() => _handler.stop();
|
||||||
|
|
||||||
|
Future<void> setVolumen(double vol) => _handler.setVolume(vol.clamp(0.0, 1.0));
|
||||||
|
|
||||||
|
double get volumen => _handler.volumen;
|
||||||
|
bool get estaSonando => _handler.playbackState.value.playing;
|
||||||
|
|
||||||
|
/// No-op: el handler se limpia en main.dart al cerrar la app.
|
||||||
|
Future<void> dispose() async {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
// AudioHandler — núcleo del audio en background
|
||||||
|
// ─────────────────────────────────────────────────────────────
|
||||||
|
|
||||||
|
/// Handler de audio_service.
|
||||||
|
///
|
||||||
|
/// Gestiona la reproducción con `just_audio` y mantiene la notificación
|
||||||
|
/// foreground activa mientras hay audio reproduciéndose.
|
||||||
|
///
|
||||||
|
/// ### Inicialización en main.dart
|
||||||
|
/// ```dart
|
||||||
|
/// final handler = await AudioService.init(
|
||||||
|
/// builder: () => PluriWaveAudioHandler(),
|
||||||
|
/// config: const AudioServiceConfig(
|
||||||
|
/// androidNotificationChannelId: 'es.freetimelab.pluriwave.audio',
|
||||||
|
/// androidNotificationChannelName: 'PluriWave Radio',
|
||||||
|
/// androidNotificationOngoing: true,
|
||||||
|
/// androidStopForegroundOnPause: true,
|
||||||
|
/// androidNotificationIcon: 'drawable/ic_stat_radio',
|
||||||
|
/// ),
|
||||||
|
/// );
|
||||||
|
/// registrarHandler(handler);
|
||||||
|
/// ```
|
||||||
|
class PluriWaveAudioHandler extends BaseAudioHandler with SeekHandler {
|
||||||
|
final AudioPlayer _player = AudioPlayer();
|
||||||
|
Emisora? emisoraActual;
|
||||||
|
double _volumen = 1.0;
|
||||||
|
double get volumen => _volumen;
|
||||||
|
|
||||||
|
PluriWaveAudioHandler() {
|
||||||
|
_setupStreams();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _setupStreams() {
|
||||||
|
// Propagar estado del player → playbackState (lo que ve la notificación)
|
||||||
|
_player.playerStateStream.listen((state) {
|
||||||
|
final playing = state.playing;
|
||||||
|
final proc = state.processingState;
|
||||||
|
|
||||||
|
playbackState.add(playbackState.value.copyWith(
|
||||||
|
controls: [
|
||||||
|
if (playing) MediaControl.pause else MediaControl.play,
|
||||||
|
MediaControl.stop,
|
||||||
|
],
|
||||||
|
systemActions: const {MediaAction.seek, MediaAction.stop},
|
||||||
|
androidCompactActionIndices: const [0],
|
||||||
|
processingState: _mapProcState(proc),
|
||||||
|
playing: playing,
|
||||||
|
bufferedPosition: _player.bufferedPosition,
|
||||||
|
speed: _player.speed,
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Actualizar bufferedPosition
|
||||||
|
_player.bufferedPositionStream.listen((pos) {
|
||||||
|
playbackState.add(playbackState.value.copyWith(bufferedPosition: pos));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
AudioProcessingState _mapProcState(ProcessingState state) {
|
||||||
|
return switch (state) {
|
||||||
|
ProcessingState.idle => AudioProcessingState.idle,
|
||||||
|
ProcessingState.loading => AudioProcessingState.loading,
|
||||||
|
ProcessingState.buffering => AudioProcessingState.buffering,
|
||||||
|
ProcessingState.ready => AudioProcessingState.ready,
|
||||||
|
ProcessingState.completed => AudioProcessingState.completed,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> playMediaItem(MediaItem item) async {
|
||||||
|
mediaItem.add(item);
|
||||||
|
try {
|
||||||
|
await _player.stop();
|
||||||
|
await _player.setUrl(item.id);
|
||||||
|
await _player.play();
|
||||||
|
} on PlayerException catch (e) {
|
||||||
|
playbackState.add(playbackState.value.copyWith(
|
||||||
|
processingState: AudioProcessingState.error,
|
||||||
|
errorMessage: e.message ?? 'Error de reproducción',
|
||||||
|
errorCode: e.code,
|
||||||
|
));
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> play() => _player.play();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> pause() => _player.pause();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> stop() async {
|
||||||
|
await _player.stop();
|
||||||
|
emisoraActual = null;
|
||||||
|
mediaItem.add(null);
|
||||||
|
await super.stop();
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> seek(Duration position) => _player.seek(position);
|
||||||
|
|
||||||
|
Future<void> setVolume(double vol) async {
|
||||||
|
_volumen = vol.clamp(0.0, 1.0);
|
||||||
|
await _player.setVolume(_volumen);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<void> onTaskRemoved() async {
|
||||||
|
await stop();
|
||||||
|
await _player.dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,251 +1,125 @@
|
|||||||
import 'package:path/path.dart';
|
import 'package:path/path.dart';
|
||||||
import 'package:sqflite/sqflite.dart';
|
import 'package:sqflite/sqflite.dart';
|
||||||
|
|
||||||
import '../modelos/emisora.dart';
|
import '../modelos/emisora.dart';
|
||||||
|
|
||||||
/// Servicio de persistencia de emisoras favoritas con SQLite (sqflite).
|
/// Servicio de persistencia de emisoras favoritas con SQLite.
|
||||||
///
|
///
|
||||||
/// ### Inicialización lazy
|
/// - Inicialización lazy: la BD se abre en el primer acceso.
|
||||||
/// La base de datos se abre en el primer acceso; no es necesario llamar
|
/// - Migration-ready: versión 2 añade campos de la Radio Browser API.
|
||||||
/// a ningún método `init()` explícito.
|
|
||||||
///
|
|
||||||
/// ### Migration-ready
|
|
||||||
/// El esquema está versionado (`_dbVersion`). Para añadir columnas en una
|
|
||||||
/// versión futura, implementa el caso correspondiente en `_onUpgrade`.
|
|
||||||
/// La versión actual es **1**.
|
|
||||||
///
|
|
||||||
/// ### Eliminación lógica
|
|
||||||
/// No se borran filas físicas sin confirmación explícita. El método
|
|
||||||
/// [eliminar] hace `DELETE` por `uuid` (la tabla de favoritos es propiedad
|
|
||||||
/// del usuario y el borrado es una acción explícita y reversible vía
|
|
||||||
/// [agregar]). Si en el futuro se requiere eliminación lógica, añade la
|
|
||||||
/// columna `eliminado` en la migración a versión 2.
|
|
||||||
///
|
|
||||||
/// ### Uso básico
|
|
||||||
/// ```dart
|
|
||||||
/// final servicio = ServicioFavoritos();
|
|
||||||
///
|
|
||||||
/// await servicio.agregar(emisora);
|
|
||||||
/// final lista = await servicio.obtenerTodos();
|
|
||||||
/// final esFav = await servicio.esFavorito('some-uuid');
|
|
||||||
/// await servicio.reordenar('some-uuid', 3);
|
|
||||||
/// await servicio.eliminar('some-uuid');
|
|
||||||
/// ```
|
|
||||||
class ServicioFavoritos {
|
class ServicioFavoritos {
|
||||||
// ─── Constantes de esquema ────────────────────────────────────────────────
|
static const _dbName = 'pluriwave.db';
|
||||||
|
static const _dbVersion = 2;
|
||||||
static const String _dbNombre = 'pluriwave.db';
|
|
||||||
static const int _dbVersion = 1;
|
|
||||||
|
|
||||||
static const String _tabla = 'favoritos';
|
|
||||||
|
|
||||||
// Columnas
|
|
||||||
static const String _colId = 'id';
|
|
||||||
static const String _colUuid = 'uuid';
|
|
||||||
static const String _colNombre = 'nombre';
|
|
||||||
static const String _colUrl = 'url';
|
|
||||||
static const String _colFavicon = 'favicon';
|
|
||||||
static const String _colPais = 'pais';
|
|
||||||
static const String _colIdioma = 'idioma';
|
|
||||||
static const String _colTags = 'tags';
|
|
||||||
static const String _colOrden = 'orden';
|
|
||||||
|
|
||||||
// ─── Estado interno ───────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/// Instancia única del servicio (singleton ligero).
|
|
||||||
static final ServicioFavoritos _instancia = ServicioFavoritos._interno();
|
|
||||||
|
|
||||||
factory ServicioFavoritos() => _instancia;
|
|
||||||
|
|
||||||
ServicioFavoritos._interno();
|
|
||||||
|
|
||||||
Database? _db;
|
Database? _db;
|
||||||
|
|
||||||
// ─── Acceso a la BD (lazy) ────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/// Devuelve la instancia abierta de la BD.
|
|
||||||
/// La abre y crea las tablas en el primer acceso.
|
|
||||||
Future<Database> get _database async {
|
Future<Database> get _database async {
|
||||||
_db ??= await _abrirBd();
|
_db ??= await _initDb();
|
||||||
return _db!;
|
return _db!;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<Database> _abrirBd() async {
|
Future<Database> _initDb() async {
|
||||||
final ruta = join(await getDatabasesPath(), _dbNombre);
|
final dbPath = await getDatabasesPath();
|
||||||
|
final path = join(dbPath, _dbName);
|
||||||
return openDatabase(
|
return openDatabase(
|
||||||
ruta,
|
path,
|
||||||
version: _dbVersion,
|
version: _dbVersion,
|
||||||
onCreate: _onCreate,
|
onCreate: _onCreate,
|
||||||
onUpgrade: _onUpgrade,
|
onUpgrade: _onUpgrade,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── Callbacks de ciclo de vida de la BD ─────────────────────────────────
|
|
||||||
|
|
||||||
/// Crea el esquema inicial (versión 1).
|
|
||||||
Future<void> _onCreate(Database db, int version) async {
|
Future<void> _onCreate(Database db, int version) async {
|
||||||
await db.execute('''
|
await db.execute('''
|
||||||
CREATE TABLE IF NOT EXISTS $_tabla (
|
CREATE TABLE favoritos (
|
||||||
$_colId INTEGER PRIMARY KEY AUTOINCREMENT,
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
$_colUuid TEXT NOT NULL UNIQUE,
|
uuid TEXT NOT NULL UNIQUE,
|
||||||
$_colNombre TEXT NOT NULL,
|
nombre TEXT NOT NULL,
|
||||||
$_colUrl TEXT NOT NULL,
|
url TEXT NOT NULL,
|
||||||
$_colFavicon TEXT,
|
favicon TEXT,
|
||||||
$_colPais TEXT,
|
pais TEXT,
|
||||||
$_colIdioma TEXT,
|
codigo_pais TEXT,
|
||||||
$_colTags TEXT,
|
idioma TEXT,
|
||||||
$_colOrden INTEGER NOT NULL DEFAULT 0
|
tags TEXT,
|
||||||
|
codec TEXT,
|
||||||
|
bitrate INTEGER,
|
||||||
|
votes INTEGER NOT NULL DEFAULT 0,
|
||||||
|
clickcount INTEGER NOT NULL DEFAULT 0,
|
||||||
|
orden INTEGER NOT NULL DEFAULT 0
|
||||||
)
|
)
|
||||||
''');
|
''');
|
||||||
|
|
||||||
// Índice para búsquedas frecuentes por uuid
|
|
||||||
await db.execute(
|
|
||||||
'CREATE UNIQUE INDEX IF NOT EXISTS idx_favoritos_uuid ON $_tabla ($_colUuid)',
|
|
||||||
);
|
|
||||||
|
|
||||||
// Índice para ordenación
|
|
||||||
await db.execute(
|
|
||||||
'CREATE INDEX IF NOT EXISTS idx_favoritos_orden ON $_tabla ($_colOrden)',
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Migraciones futuras.
|
|
||||||
///
|
|
||||||
/// Añade un `case` por cada nueva versión. No uses `DROP COLUMN` —
|
|
||||||
/// marca la columna como obsoleta y elimínala en el siguiente sprint.
|
|
||||||
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
|
Future<void> _onUpgrade(Database db, int oldVersion, int newVersion) async {
|
||||||
for (var v = oldVersion + 1; v <= newVersion; v++) {
|
if (oldVersion < 2) {
|
||||||
switch (v) {
|
// v1→v2: añadir columnas de la Radio Browser API
|
||||||
// Ejemplo para versión 2:
|
await db.execute('ALTER TABLE favoritos ADD COLUMN codigo_pais TEXT');
|
||||||
// case 2:
|
await db.execute('ALTER TABLE favoritos ADD COLUMN codec TEXT');
|
||||||
// await db.execute(
|
await db.execute('ALTER TABLE favoritos ADD COLUMN bitrate INTEGER');
|
||||||
// 'ALTER TABLE $_tabla ADD COLUMN nueva_col TEXT',
|
await db.execute('ALTER TABLE favoritos ADD COLUMN votes INTEGER NOT NULL DEFAULT 0');
|
||||||
// );
|
await db.execute('ALTER TABLE favoritos ADD COLUMN clickcount INTEGER NOT NULL DEFAULT 0');
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ─── API pública ──────────────────────────────────────────────────────────
|
/// Devuelve todas las emisoras favoritas ordenadas por [orden].
|
||||||
|
|
||||||
/// Devuelve todas las emisoras favoritas ordenadas por [_colOrden] ASC.
|
|
||||||
///
|
|
||||||
/// Nunca devuelve null; devuelve lista vacía si no hay favoritos.
|
|
||||||
Future<List<Emisora>> obtenerTodos() async {
|
Future<List<Emisora>> obtenerTodos() async {
|
||||||
final db = await _database;
|
final db = await _database;
|
||||||
final filas = await db.query(
|
final rows = await db.query('favoritos', orderBy: 'orden ASC');
|
||||||
_tabla,
|
return rows.map(Emisora.fromMap).toList();
|
||||||
orderBy: '$_colOrden ASC, $_colId ASC',
|
|
||||||
);
|
|
||||||
return filas.map(Emisora.fromMap).toList();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Agrega [emisora] a la lista de favoritos.
|
/// Añade una emisora a favoritos. Si ya existe (mismo uuid), la actualiza.
|
||||||
///
|
Future<void> agregar(Emisora emisora) async {
|
||||||
/// Si ya existe una emisora con el mismo [Emisora.uuid], actualiza todos
|
|
||||||
/// sus campos (upsert). El campo [Emisora.orden] se asigna al final de la
|
|
||||||
/// lista cuando su valor es 0 y la emisora es nueva.
|
|
||||||
///
|
|
||||||
/// Devuelve el [id] de la fila insertada o actualizada.
|
|
||||||
Future<int> agregar(Emisora emisora) async {
|
|
||||||
final db = await _database;
|
final db = await _database;
|
||||||
|
// Calcular el siguiente orden
|
||||||
// Calcular orden automático si viene en 0 y la emisora es nueva
|
final maxOrden = Sqflite.firstIntValue(
|
||||||
Emisora emisoraFinal = emisora;
|
await db.rawQuery('SELECT MAX(orden) FROM favoritos'),
|
||||||
if (emisora.orden == 0) {
|
) ??
|
||||||
final existe = await esFavorito(emisora.uuid);
|
-1;
|
||||||
if (!existe) {
|
final nuevaEmisora = emisora.copyWith(orden: maxOrden + 1);
|
||||||
final maxOrden = await _maxOrden(db);
|
await db.insert(
|
||||||
emisoraFinal = emisora.copyWith(orden: maxOrden + 1);
|
'favoritos',
|
||||||
}
|
nuevaEmisora.toMap(),
|
||||||
}
|
|
||||||
|
|
||||||
return db.insert(
|
|
||||||
_tabla,
|
|
||||||
emisoraFinal.toMap(),
|
|
||||||
conflictAlgorithm: ConflictAlgorithm.replace,
|
conflictAlgorithm: ConflictAlgorithm.replace,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Elimina la emisora con [uuid] de la lista de favoritos.
|
/// Elimina una emisora de favoritos por [uuid].
|
||||||
///
|
Future<void> eliminar(String uuid) async {
|
||||||
/// Si la emisora no existe, no hace nada (idempotente).
|
|
||||||
/// Devuelve el número de filas eliminadas (0 ó 1).
|
|
||||||
Future<int> eliminar(String uuid) async {
|
|
||||||
final db = await _database;
|
final db = await _database;
|
||||||
return db.delete(
|
await db.delete('favoritos', where: 'uuid = ?', whereArgs: [uuid]);
|
||||||
_tabla,
|
|
||||||
where: '$_colUuid = ?',
|
|
||||||
whereArgs: [uuid],
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Devuelve `true` si la emisora con [uuid] está en la lista de favoritos.
|
/// Devuelve true si la emisora con [uuid] está en favoritos.
|
||||||
Future<bool> esFavorito(String uuid) async {
|
Future<bool> esFavorito(String uuid) async {
|
||||||
final db = await _database;
|
final db = await _database;
|
||||||
final resultado = await db.query(
|
final count = Sqflite.firstIntValue(
|
||||||
_tabla,
|
await db.rawQuery(
|
||||||
columns: [_colId],
|
'SELECT COUNT(*) FROM favoritos WHERE uuid = ?',
|
||||||
where: '$_colUuid = ?',
|
[uuid],
|
||||||
whereArgs: [uuid],
|
),
|
||||||
limit: 1,
|
|
||||||
);
|
);
|
||||||
return resultado.isNotEmpty;
|
return (count ?? 0) > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Actualiza el [orden] de la emisora con [uuid] al valor [nuevoOrden].
|
/// Alterna el estado de favorito de una emisora.
|
||||||
///
|
Future<bool> toggleFavorito(Emisora emisora) async {
|
||||||
/// Si la emisora no existe, no hace nada (idempotente).
|
if (await esFavorito(emisora.uuid)) {
|
||||||
/// Devuelve el número de filas actualizadas (0 ó 1).
|
await eliminar(emisora.uuid);
|
||||||
///
|
return false;
|
||||||
/// Nota: este método actualiza solo la columna `orden` de la emisora
|
} else {
|
||||||
/// indicada. Si necesitas reordenar toda la lista de una vez (drag & drop),
|
await agregar(emisora);
|
||||||
/// construye una lista ordenada y llama a [reordenarLista].
|
return true;
|
||||||
Future<int> reordenar(String uuid, int nuevoOrden) async {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Actualiza el orden de un favorito.
|
||||||
|
Future<void> reordenar(String uuid, int nuevoOrden) async {
|
||||||
final db = await _database;
|
final db = await _database;
|
||||||
return db.update(
|
await db.update(
|
||||||
_tabla,
|
'favoritos',
|
||||||
{_colOrden: nuevoOrden},
|
{'orden': nuevoOrden},
|
||||||
where: '$_colUuid = ?',
|
where: 'uuid = ?',
|
||||||
whereArgs: [uuid],
|
whereArgs: [uuid],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reordena la lista completa de favoritos en una sola transacción.
|
|
||||||
///
|
|
||||||
/// Recibe una lista ordenada de UUIDs y asigna el orden 0, 1, 2... en
|
|
||||||
/// el mismo orden. Ideal para operaciones de drag & drop.
|
|
||||||
Future<void> reordenarLista(List<String> uuidsOrdenados) async {
|
|
||||||
final db = await _database;
|
|
||||||
await db.transaction((txn) async {
|
|
||||||
for (var i = 0; i < uuidsOrdenados.length; i++) {
|
|
||||||
await txn.update(
|
|
||||||
_tabla,
|
|
||||||
{_colOrden: i},
|
|
||||||
where: '$_colUuid = ?',
|
|
||||||
whereArgs: [uuidsOrdenados[i]],
|
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Devuelve el número total de emisoras favoritas.
|
|
||||||
Future<int> contarFavoritos() async {
|
|
||||||
final db = await _database;
|
|
||||||
final resultado = await db.rawQuery(
|
|
||||||
'SELECT COUNT(*) AS total FROM $_tabla',
|
|
||||||
);
|
|
||||||
return resultado.first['total'] as int? ?? 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// ─── Helpers privados ─────────────────────────────────────────────────────
|
|
||||||
|
|
||||||
/// Devuelve el valor máximo actual de [_colOrden], o 0 si la tabla está vacía.
|
|
||||||
Future<int> _maxOrden(Database db) async {
|
|
||||||
final resultado = await db.rawQuery(
|
|
||||||
'SELECT MAX($_colOrden) AS max_orden FROM $_tabla',
|
|
||||||
);
|
|
||||||
return resultado.first['max_orden'] as int? ?? 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
148
lib/servicios/servicio_radio.dart
Normal file
@@ -0,0 +1,148 @@
|
|||||||
|
import 'dart:convert';
|
||||||
|
import 'dart:math';
|
||||||
|
import 'package:http/http.dart' as http;
|
||||||
|
import '../modelos/emisora.dart';
|
||||||
|
|
||||||
|
/// Cliente para la Radio Browser API (https://api.radio-browser.info/).
|
||||||
|
///
|
||||||
|
/// Selecciona automáticamente un servidor disponible de entre los DNS
|
||||||
|
/// resueltos para `all.api.radio-browser.info` y rota en caso de error.
|
||||||
|
///
|
||||||
|
/// ### Rate limiting
|
||||||
|
/// La API no tiene límite documentado, pero por cortesía limitamos a
|
||||||
|
/// peticiones con `?limit` explícito y no hacemos polling automático.
|
||||||
|
class ServicioRadio {
|
||||||
|
static const _dnsHost = 'all.api.radio-browser.info';
|
||||||
|
static const _timeout = Duration(seconds: 10);
|
||||||
|
|
||||||
|
// Servidores conocidos como fallback si el DNS falla
|
||||||
|
static const _servidoresFallback = [
|
||||||
|
'de1.api.radio-browser.info',
|
||||||
|
'nl1.api.radio-browser.info',
|
||||||
|
'at1.api.radio-browser.info',
|
||||||
|
];
|
||||||
|
|
||||||
|
String? _servidorActual;
|
||||||
|
|
||||||
|
Future<String> _servidor() async {
|
||||||
|
if (_servidorActual != null) return _servidorActual!;
|
||||||
|
// Intentar DNS lookup simplificado — usamos fallback directamente
|
||||||
|
final servidores = List<String>.from(_servidoresFallback)..shuffle(Random());
|
||||||
|
_servidorActual = servidores.first;
|
||||||
|
return _servidorActual!;
|
||||||
|
}
|
||||||
|
|
||||||
|
Uri _uri(String servidor, String path, Map<String, String> params) {
|
||||||
|
return Uri.https(servidor, path, {
|
||||||
|
'hidebroken': 'true',
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<List<Emisora>> _get(String path, Map<String, String> params) async {
|
||||||
|
final servidor = await _servidor();
|
||||||
|
// lastcheckok=1 filtra emisoras que la API verificó como funcionales
|
||||||
|
final uri = _uri(servidor, path, {
|
||||||
|
'lastcheckok': '1',
|
||||||
|
...params,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
final resp = await http.get(uri, headers: {
|
||||||
|
'User-Agent': 'PluriWave/0.1.0 (es.freetimelab.pluriwave)',
|
||||||
|
}).timeout(_timeout);
|
||||||
|
|
||||||
|
if (resp.statusCode != 200) {
|
||||||
|
throw Exception('API error ${resp.statusCode}');
|
||||||
|
}
|
||||||
|
final lista = json.decode(resp.body) as List<dynamic>;
|
||||||
|
return lista
|
||||||
|
.cast<Map<String, dynamic>>()
|
||||||
|
.map(Emisora.fromApi)
|
||||||
|
.where((e) => e.uuid.isNotEmpty && e.url.isNotEmpty)
|
||||||
|
.toList();
|
||||||
|
} catch (e) {
|
||||||
|
// Rotar servidor en el siguiente intento
|
||||||
|
_servidorActual = null;
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Emisoras más votadas globalmente.
|
||||||
|
Future<List<Emisora>> obtenerPopulares({int limit = 30}) async {
|
||||||
|
return _get('/json/stations/topvote/$limit', {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Emisoras más escuchadas (por clicks) globalmente.
|
||||||
|
Future<List<Emisora>> obtenerTendencias({int limit = 20}) async {
|
||||||
|
return _get('/json/stations/topclick/$limit', {});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Buscar por nombre de emisora.
|
||||||
|
Future<List<Emisora>> buscarPorNombre(String query, {int limit = 30}) async {
|
||||||
|
return _get('/json/stations/search', {
|
||||||
|
'name': query,
|
||||||
|
'limit': limit.toString(),
|
||||||
|
'order': 'votes',
|
||||||
|
'reverse': 'true',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Buscar por código de país (ISO 3166-1 alpha-2, e.g. 'ES', 'US').
|
||||||
|
Future<List<Emisora>> buscarPorPais(String codigoPais, {int limit = 50}) async {
|
||||||
|
return _get('/json/stations/bycountrycodeexact/$codigoPais', {
|
||||||
|
'limit': limit.toString(),
|
||||||
|
'order': 'votes',
|
||||||
|
'reverse': 'true',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Buscar por idioma (e.g. 'spanish', 'english').
|
||||||
|
Future<List<Emisora>> buscarPorIdioma(String idioma, {int limit = 30}) async {
|
||||||
|
return _get('/json/stations/bylanguageexact/$idioma', {
|
||||||
|
'limit': limit.toString(),
|
||||||
|
'order': 'votes',
|
||||||
|
'reverse': 'true',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Buscar por tag/género (e.g. 'rock', 'jazz', 'pop').
|
||||||
|
Future<List<Emisora>> buscarPorTag(String tag, {int limit = 30}) async {
|
||||||
|
return _get('/json/stations/bytagexact/$tag', {
|
||||||
|
'limit': limit.toString(),
|
||||||
|
'order': 'votes',
|
||||||
|
'reverse': 'true',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Búsqueda combinada: permite combinar nombre, país, idioma y tag.
|
||||||
|
Future<List<Emisora>> buscar({
|
||||||
|
String? nombre,
|
||||||
|
String? pais,
|
||||||
|
String? idioma,
|
||||||
|
String? tag,
|
||||||
|
int limit = 30,
|
||||||
|
}) async {
|
||||||
|
return _get('/json/stations/search', {
|
||||||
|
if (nombre != null && nombre.isNotEmpty) 'name': nombre,
|
||||||
|
if (pais != null && pais.isNotEmpty) 'countrycode': pais,
|
||||||
|
if (idioma != null && idioma.isNotEmpty) 'language': idioma,
|
||||||
|
if (tag != null && tag.isNotEmpty) 'tag': tag,
|
||||||
|
'limit': limit.toString(),
|
||||||
|
'order': 'votes',
|
||||||
|
'reverse': 'true',
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Registrar un click en la API (buenas prácticas de ciudadanía API).
|
||||||
|
Future<void> registrarClick(String uuid) async {
|
||||||
|
try {
|
||||||
|
final servidor = await _servidor();
|
||||||
|
await http.get(
|
||||||
|
Uri.https(servidor, '/json/url/$uuid'),
|
||||||
|
headers: {'User-Agent': 'PluriWave/0.1.0 (es.freetimelab.pluriwave)'},
|
||||||
|
).timeout(_timeout);
|
||||||
|
} catch (_) {
|
||||||
|
// No crítico — ignorar silenciosamente
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
97
lib/servicios/servicio_timer.dart
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'servicio_audio.dart';
|
||||||
|
|
||||||
|
/// Opciones predefinidas de timer en minutos.
|
||||||
|
const opcionesTimer = [15, 30, 60, 90];
|
||||||
|
|
||||||
|
/// Servicio de auto-apagado de la radio.
|
||||||
|
///
|
||||||
|
/// Cuenta atrás desde la duración elegida. Cuando llega a 0:
|
||||||
|
/// 1. Hace un fade out de [_fadeDuracion] segundos.
|
||||||
|
/// 2. Llama a [ServicioAudio.detener].
|
||||||
|
///
|
||||||
|
/// El UI puede escuchar [tiempoRestanteStream] para mostrar el contador.
|
||||||
|
class ServicioTimer {
|
||||||
|
final ServicioAudio _audio;
|
||||||
|
|
||||||
|
Timer? _timer;
|
||||||
|
Timer? _fadeTicker;
|
||||||
|
DateTime? _finAt;
|
||||||
|
Duration _tiempoRestante = Duration.zero;
|
||||||
|
bool _activo = false;
|
||||||
|
|
||||||
|
static const _fadeDuracion = Duration(seconds: 30);
|
||||||
|
static const _fadeStep = Duration(seconds: 1);
|
||||||
|
|
||||||
|
final _controller = StreamController<Duration>.broadcast();
|
||||||
|
|
||||||
|
ServicioTimer(this._audio);
|
||||||
|
|
||||||
|
/// Stream que emite el tiempo restante cada segundo.
|
||||||
|
Stream<Duration> get tiempoRestanteStream => _controller.stream;
|
||||||
|
Duration get tiempoRestante => _tiempoRestante;
|
||||||
|
bool get activo => _activo;
|
||||||
|
|
||||||
|
/// Inicia el timer para [minutos] minutos.
|
||||||
|
void iniciar(int minutos) {
|
||||||
|
cancelar();
|
||||||
|
final duracion = Duration(minutes: minutos);
|
||||||
|
_finAt = DateTime.now().add(duracion);
|
||||||
|
_tiempoRestante = duracion;
|
||||||
|
_activo = true;
|
||||||
|
_controller.add(_tiempoRestante);
|
||||||
|
|
||||||
|
_timer = Timer.periodic(const Duration(seconds: 1), (_) {
|
||||||
|
final ahora = DateTime.now();
|
||||||
|
final restante = _finAt!.difference(ahora);
|
||||||
|
|
||||||
|
if (restante <= Duration.zero) {
|
||||||
|
_tiempoRestante = Duration.zero;
|
||||||
|
_controller.add(_tiempoRestante);
|
||||||
|
_iniciarFadeOut();
|
||||||
|
cancelar(detenerAudio: false);
|
||||||
|
} else {
|
||||||
|
_tiempoRestante = restante;
|
||||||
|
_controller.add(_tiempoRestante);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void _iniciarFadeOut() {
|
||||||
|
final pasos = _fadeDuracion.inSeconds;
|
||||||
|
final volumenInicial = _audio.volumen;
|
||||||
|
int paso = 0;
|
||||||
|
|
||||||
|
_fadeTicker = Timer.periodic(_fadeStep, (_) async {
|
||||||
|
paso++;
|
||||||
|
final nuevoVolumen = volumenInicial * (1 - paso / pasos);
|
||||||
|
await _audio.setVolumen(nuevoVolumen.clamp(0.0, 1.0));
|
||||||
|
|
||||||
|
if (paso >= pasos) {
|
||||||
|
_fadeTicker?.cancel();
|
||||||
|
await _audio.detener();
|
||||||
|
await _audio.setVolumen(volumenInicial); // restaurar volumen para próxima vez
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Cancela el timer activo sin detener el audio.
|
||||||
|
void cancelar({bool detenerAudio = false}) {
|
||||||
|
_timer?.cancel();
|
||||||
|
_timer = null;
|
||||||
|
_fadeTicker?.cancel();
|
||||||
|
_fadeTicker = null;
|
||||||
|
_activo = false;
|
||||||
|
_tiempoRestante = Duration.zero;
|
||||||
|
_controller.add(_tiempoRestante);
|
||||||
|
|
||||||
|
if (detenerAudio) {
|
||||||
|
_audio.detener();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void dispose() {
|
||||||
|
cancelar();
|
||||||
|
_controller.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
124
lib/widgets/mini_reproductor.dart
Normal file
@@ -0,0 +1,124 @@
|
|||||||
|
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';
|
||||||
|
|
||||||
|
/// 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: [
|
||||||
|
// Logo
|
||||||
|
ClipRRect(
|
||||||
|
borderRadius: BorderRadius.circular(6),
|
||||||
|
child: Container(
|
||||||
|
width: 40,
|
||||||
|
height: 40,
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
child: Icon(Icons.radio,
|
||||||
|
size: 22,
|
||||||
|
color: theme.colorScheme.onPrimaryContainer),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
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',
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
135
lib/widgets/tarjeta_emisora.dart
Normal file
@@ -0,0 +1,135 @@
|
|||||||
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:shimmer/shimmer.dart';
|
||||||
|
import '../modelos/emisora.dart';
|
||||||
|
|
||||||
|
/// Tarjeta compacta para mostrar una emisora en listas y grids.
|
||||||
|
class TarjetaEmisora extends StatelessWidget {
|
||||||
|
final Emisora emisora;
|
||||||
|
final VoidCallback? onTap;
|
||||||
|
final bool esCompacta;
|
||||||
|
|
||||||
|
const TarjetaEmisora({
|
||||||
|
super.key,
|
||||||
|
required this.emisora,
|
||||||
|
this.onTap,
|
||||||
|
this.esCompacta = false,
|
||||||
|
});
|
||||||
|
|
||||||
|
@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),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCompleta(ThemeData theme) {
|
||||||
|
return Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
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,
|
||||||
|
),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _buildCompacta(ThemeData theme) {
|
||||||
|
return ListTile(
|
||||||
|
leading: SizedBox(width: 48, height: 48, child: _logo(theme, 24)),
|
||||||
|
title: Text(
|
||||||
|
emisora.nombre,
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
subtitle: Text(
|
||||||
|
[emisora.pais, emisora.idioma].where((s) => s != null).join(' · '),
|
||||||
|
maxLines: 1,
|
||||||
|
overflow: TextOverflow.ellipsis,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _logo(ThemeData theme, double iconSize) {
|
||||||
|
if (emisora.favicon != null && emisora.favicon!.isNotEmpty) {
|
||||||
|
return CachedNetworkImage(
|
||||||
|
imageUrl: emisora.favicon!,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
placeholder: (_, __) => _shimmer(theme),
|
||||||
|
errorWidget: (_, __, ___) => _iconoFallback(theme, iconSize),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return _iconoFallback(theme, iconSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _shimmer(ThemeData theme) {
|
||||||
|
return Shimmer.fromColors(
|
||||||
|
baseColor: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
highlightColor: theme.colorScheme.surface,
|
||||||
|
child: Container(color: theme.colorScheme.surfaceContainerHighest),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Widget _iconoFallback(ThemeData theme, double size) {
|
||||||
|
return Container(
|
||||||
|
color: theme.colorScheme.primaryContainer,
|
||||||
|
child: Icon(Icons.radio, size: size, color: theme.colorScheme.onPrimaryContainer),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Placeholder shimmer para listas en carga.
|
||||||
|
class TarjetaEmisoraShimmer extends StatelessWidget {
|
||||||
|
const TarjetaEmisoraShimmer({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final theme = Theme.of(context);
|
||||||
|
return Shimmer.fromColors(
|
||||||
|
baseColor: theme.colorScheme.surfaceContainerHighest,
|
||||||
|
highlightColor: theme.colorScheme.surface,
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
AspectRatio(
|
||||||
|
aspectRatio: 1,
|
||||||
|
child: Container(color: theme.colorScheme.surfaceContainerHighest),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 8),
|
||||||
|
Container(height: 14, color: theme.colorScheme.surfaceContainerHighest),
|
||||||
|
const SizedBox(height: 4),
|
||||||
|
Container(height: 12, width: 60, color: theme.colorScheme.surfaceContainerHighest),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||