feat(iap): add freemium unlock via one-time in-app purchase
Adds a permanent, non-consumable premium unlock (EstadoEntitlement + PuertoCompras/ServicioComprasPlayBilling) that removes ads and unlocks alarm vacations, alarms past a 5-alarm free cap, recording start, and full Android Auto browsing. The phone equalizer stays free for everyone. - Entitlement is prefs-backed (compra_premium_v1), fail-open, and resolvable headlessly via esPremiumPersistido() for the Android Auto audio handler, which registers before runApp. - Android Auto reduced mode keeps the real root folder labels for free users; browsing into any of them (and playFromMediaId/playFromSearch/ skipToNext/skipToPrevious) is blocked at the getChildren/servicio_audio choke points, with a locked "Función Premium" item as the backstop. Current-station play/pause/stop stays untouched. A free -> premium transition actively invalidates the head unit's cached browse tree. - Ads (top banner + capped interstitial before adding a station or an alarm) are gated behind entitlement via ServicioAnuncios, using official Google test ad unit IDs pending AdMob provisioning. - Alarm cap UX shows an explanatory message with a secondary unlock action rather than a bare paywall jump; existing data is grandfathered. - 4 new localization keys translated across all 13 supported locales. Co-located tests use strict TDD (RED test before implementation) for every new pure-logic unit; full existing suite passes unchanged.
This commit is contained in:
@@ -6,6 +6,7 @@ import '../../estado/estado_radio.dart';
|
||||
import '../../l10n/display_names.dart';
|
||||
import '../../l10n/gen/app_localizations.dart';
|
||||
import '../../modelos/emisora.dart';
|
||||
import '../../servicios/servicio_anuncios.dart';
|
||||
import '../../widgets/pluri_glass_surface.dart';
|
||||
import '../../widgets/pluri_layout.dart';
|
||||
import '../../widgets/pluri_push_scaffold.dart';
|
||||
@@ -105,6 +106,11 @@ class _CuerpoEmisorasPersonalizadas extends StatelessWidget {
|
||||
}
|
||||
|
||||
Future<void> _mostrarFormularioAnadir(BuildContext context) async {
|
||||
// ad-display spec "Interstitial Before Manual Station Add" (design.md
|
||||
// ADR-6): fires on the CTA tap, before the form even opens — a no-op
|
||||
// for premium (ServicioAnuncios' own entitlement gate).
|
||||
await context.read<ServicioAnuncios>().intentarInterstitial();
|
||||
if (!context.mounted) return;
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../estado/estado_ecualizador.dart';
|
||||
import '../estado/estado_entitlement.dart';
|
||||
import '../estado/estado_grabacion.dart';
|
||||
import '../estado/estado_idioma.dart';
|
||||
import '../estado/estado_radio.dart';
|
||||
@@ -10,6 +11,7 @@ import '../l10n/gen/app_localizations.dart';
|
||||
import '../modelos/archivo_grabacion.dart';
|
||||
import '../modelos/emisora.dart';
|
||||
import '../tema/pluriwave_tokens.dart';
|
||||
import '../widgets/hoja_premium.dart';
|
||||
import '../widgets/pluri_layout.dart';
|
||||
import '../widgets/pluri_push_scaffold.dart';
|
||||
import '../widgets/pluri_root_header.dart';
|
||||
@@ -99,6 +101,9 @@ class _AjustesContent extends StatelessWidget {
|
||||
final idioma = context.select<EstadoIdioma, Locale?>(
|
||||
(e) => e.localeSeleccionado,
|
||||
);
|
||||
final esPremium = context.select<EstadoEntitlement, bool>(
|
||||
(e) => e.esPremium,
|
||||
);
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
@@ -256,6 +261,18 @@ class _AjustesContent extends StatelessWidget {
|
||||
GrupoAjustes(
|
||||
titulo: l10n.settingsGroupApplicationTitle,
|
||||
filas: [
|
||||
// freemium-gating spec "Settings always shows a premium row":
|
||||
// a persistent buy row (free tier) or a premium-active state
|
||||
// with restore access (premium tier) — both open the same
|
||||
// paywall sheet, which adapts its own body to the tier.
|
||||
FilaAjuste(
|
||||
key: const ValueKey('ajustes-fila-premium'),
|
||||
icon: Icons.workspace_premium_rounded,
|
||||
iconColor: PluriWaveTokens.brand,
|
||||
titulo: l10n.funcionPremium,
|
||||
valor: esPremium ? l10n.equalizerActive : null,
|
||||
onTap: () => mostrarHojaPremium(context),
|
||||
),
|
||||
FilaAjuste(
|
||||
icon: Icons.language_rounded,
|
||||
titulo: l10n.languageSectionTitle,
|
||||
|
||||
@@ -9,10 +9,12 @@ import '../l10n/app_localizations_ext.dart';
|
||||
import '../l10n/gen/app_localizations.dart';
|
||||
import '../modelos/alarma_musical.dart';
|
||||
import '../modelos/emisora.dart';
|
||||
import '../servicios/servicio_anuncios.dart';
|
||||
import '../servicios/servicio_programacion_alarmas.dart';
|
||||
import '../tema/pluriwave_theme.dart';
|
||||
import '../tema/pluriwave_tokens.dart';
|
||||
import '../widgets/editor_hora_inline.dart';
|
||||
import '../widgets/hoja_premium.dart';
|
||||
import '../widgets/pluri_glass_surface.dart';
|
||||
import '../widgets/pluri_layout.dart';
|
||||
import '../widgets/pluri_push_scaffold.dart';
|
||||
@@ -105,6 +107,21 @@ class PantallaAlarmas extends StatelessWidget {
|
||||
BuildContext context, {
|
||||
AlarmaMusical? alarma,
|
||||
}) async {
|
||||
// ADR-6 ordering (design.md): for a genuinely NEW alarm (no [alarma]),
|
||||
// the cap-check + maybe-interstitial happen HERE, before the editor
|
||||
// ever opens — "puedeCrearAlarma -> if false, show the limit message
|
||||
// and no ad; if true, maybe-interstitial, then open the editor".
|
||||
// Editing an existing alarm skips both checks entirely: it is never
|
||||
// capped and never triggers the interstitial.
|
||||
if (alarma == null) {
|
||||
final estado = context.read<EstadoAlarmas>();
|
||||
if (!estado.puedeCrearAlarma()) {
|
||||
_mostrarLimiteAlarmas(context);
|
||||
return;
|
||||
}
|
||||
await context.read<ServicioAnuncios>().intentarInterstitial();
|
||||
if (!context.mounted) return;
|
||||
}
|
||||
await showModalBottomSheet<void>(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
@@ -113,6 +130,22 @@ class PantallaAlarmas extends StatelessWidget {
|
||||
builder: (_) => _EditorAlarmaSheet(alarma: alarma),
|
||||
);
|
||||
}
|
||||
|
||||
/// Freemium-gating spec "Alarm Cap UX Never Bare-Jumps To Paywall": an
|
||||
/// explanatory message with a SECONDARY unlock action — never a direct
|
||||
/// paywall navigation as the sole response to hitting the cap.
|
||||
void _mostrarLimiteAlarmas(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.limiteAlarmasAlcanzado),
|
||||
action: SnackBarAction(
|
||||
label: l10n.desbloquearPremium,
|
||||
onPressed: () => mostrarHojaPremium(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _PanelProximaAlarma extends StatelessWidget {
|
||||
@@ -1186,8 +1219,34 @@ class _EditorAlarmaSheetState extends State<_EditorAlarmaSheet> {
|
||||
sonidoInterno: _sonidoInterno,
|
||||
activa: true,
|
||||
);
|
||||
await estado.guardarAlarma(alarma);
|
||||
if (mounted) Navigator.pop(context);
|
||||
// The cap-check + interstitial already ran in `PantallaAlarmas
|
||||
// ._abrirEditor` BEFORE this sheet ever opened (ADR-6 ordering: "then
|
||||
// open the editor"). This is only the defense-in-depth backstop against
|
||||
// the state-layer choke point — e.g. a 2nd device created alarms while
|
||||
// this sheet was open — the true authority is `guardarAlarma` itself.
|
||||
final resultado = await estado.guardarAlarma(alarma);
|
||||
if (!mounted) return;
|
||||
if (resultado == ResultadoGuardarAlarma.limiteAlcanzado) {
|
||||
_mostrarLimiteAlarmas(context);
|
||||
return;
|
||||
}
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
/// Freemium-gating spec "Alarm Cap UX Never Bare-Jumps To Paywall": an
|
||||
/// explanatory message with a SECONDARY unlock action — never a direct
|
||||
/// paywall navigation as the sole response to hitting the cap.
|
||||
void _mostrarLimiteAlarmas(BuildContext context) {
|
||||
final l10n = AppLocalizations.of(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(l10n.limiteAlarmasAlcanzado),
|
||||
action: SnackBarAction(
|
||||
label: l10n.desbloquearPremium,
|
||||
onPressed: () => mostrarHojaPremium(context),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
List<Emisora> _favoritasConSeleccion(List<Emisora> favoritas) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import '../l10n/display_names.dart';
|
||||
import '../l10n/gen/app_localizations.dart';
|
||||
import '../modelos/emisora.dart';
|
||||
import '../modelos/grupo_favoritos.dart';
|
||||
import '../servicios/servicio_anuncios.dart';
|
||||
import '../tema/pluriwave_tokens.dart';
|
||||
import '../widgets/fila_emisora_plana.dart';
|
||||
import '../widgets/pluri_icon.dart';
|
||||
@@ -38,6 +39,11 @@ class _PantallaFavoritosState extends State<PantallaFavoritos> {
|
||||
String? _grupoSeleccionadoId;
|
||||
|
||||
Future<void> _abrirFormularioEmisoraPersonalizada() async {
|
||||
// ad-display spec "Interstitial Before Manual Station Add" (design.md
|
||||
// ADR-6): fires on the CTA tap, before the form even opens — a no-op
|
||||
// for premium (ServicioAnuncios' own entitlement gate).
|
||||
await context.read<ServicioAnuncios>().intentarInterstitial();
|
||||
if (!mounted) return;
|
||||
await showModalBottomSheet(
|
||||
context: context,
|
||||
isScrollControlled: true,
|
||||
|
||||
@@ -17,6 +17,7 @@ import '../tema/pluri_animate.dart';
|
||||
import '../tema/pluriwave_theme.dart';
|
||||
import '../tema/pluriwave_tokens.dart';
|
||||
import '../widgets/ecualizador_widget.dart';
|
||||
import '../widgets/hoja_premium.dart';
|
||||
import '../widgets/pluri_glass_surface.dart';
|
||||
import '../widgets/pluri_premium_widgets.dart';
|
||||
import '../widgets/pluri_push_scaffold.dart';
|
||||
@@ -597,6 +598,28 @@ class _GrabacionWidget extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
/// Freemium gate choke point at the UI layer (freemium-gating spec "Free
|
||||
/// user starts a new recording"): all 3 record-start call sites route
|
||||
/// through here. [ctx] is the picker sheet/dialog's own (short-lived)
|
||||
/// context — closed FIRST (matching the pre-existing pop-then-done shape).
|
||||
/// [contextExterno] is the screen's own longer-lived context, used ONLY to
|
||||
/// react to the AUTHORITATIVE [EstadoGrabacion.iniciar] result: a
|
||||
/// free-tier block opens the paywall there instead of a plain error, since
|
||||
/// [ctx] is already gone by then.
|
||||
Future<void> _iniciarGrabacionYCerrar(
|
||||
BuildContext ctx,
|
||||
BuildContext contextExterno,
|
||||
EstadoGrabacion grabacion, {
|
||||
Duration? duracion,
|
||||
}) async {
|
||||
final resultado = await grabacion.iniciar(duracion: duracion);
|
||||
if (ctx.mounted) Navigator.pop(ctx);
|
||||
if (resultado == ResultadoIniciarGrabacion.requierePremium &&
|
||||
contextExterno.mounted) {
|
||||
await mostrarHojaPremium(contextExterno);
|
||||
}
|
||||
}
|
||||
|
||||
void _mostrarDialogoGrabacion(BuildContext context) {
|
||||
final grabacion = context.read<EstadoGrabacion>();
|
||||
showModalBottomSheet(
|
||||
@@ -626,10 +649,12 @@ class _GrabacionWidget extends StatelessWidget {
|
||||
size: 18,
|
||||
),
|
||||
label: Text(AppLocalizations.of(ctx).indefiniteOption),
|
||||
onPressed: () {
|
||||
grabacion.iniciar();
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
onPressed:
|
||||
() => _iniciarGrabacionYCerrar(
|
||||
ctx,
|
||||
context,
|
||||
grabacion,
|
||||
),
|
||||
),
|
||||
for (final opcion in _opciones)
|
||||
ActionChip(
|
||||
@@ -642,10 +667,13 @@ class _GrabacionWidget extends StatelessWidget {
|
||||
opcion.duracion.inSeconds,
|
||||
),
|
||||
),
|
||||
onPressed: () {
|
||||
grabacion.iniciar(duracion: opcion.duracion);
|
||||
Navigator.pop(ctx);
|
||||
},
|
||||
onPressed:
|
||||
() => _iniciarGrabacionYCerrar(
|
||||
ctx,
|
||||
context,
|
||||
grabacion,
|
||||
duracion: opcion.duracion,
|
||||
),
|
||||
),
|
||||
ActionChip(
|
||||
avatar: const Icon(Icons.tune_rounded, size: 18),
|
||||
@@ -718,8 +746,12 @@ class _GrabacionWidget extends StatelessWidget {
|
||||
seconds: segundos,
|
||||
);
|
||||
if (duracion <= Duration.zero) return;
|
||||
grabacion.iniciar(duracion: duracion);
|
||||
Navigator.pop(ctx);
|
||||
_iniciarGrabacionYCerrar(
|
||||
ctx,
|
||||
context,
|
||||
grabacion,
|
||||
duracion: duracion,
|
||||
);
|
||||
},
|
||||
child: Text(AppLocalizations.of(ctx).recordAction),
|
||||
),
|
||||
|
||||
@@ -8,6 +8,7 @@ import '../l10n/gen/app_localizations.dart';
|
||||
import '../modelos/alarma_musical.dart';
|
||||
import '../tema/pluriwave_theme.dart';
|
||||
import '../tema/pluriwave_tokens.dart';
|
||||
import '../widgets/hoja_premium.dart';
|
||||
import '../widgets/pluri_glass_surface.dart';
|
||||
import '../widgets/pluri_layout.dart';
|
||||
import '../widgets/pluri_push_scaffold.dart';
|
||||
@@ -927,7 +928,14 @@ class _EditorVacacionesSheetState extends State<_EditorVacacionesSheet> {
|
||||
fin: _fin,
|
||||
nombre: nombre,
|
||||
);
|
||||
await estado.crearRangoVacaciones(rango);
|
||||
// freemium-gating spec "Gated Feature Set": vacation creation is
|
||||
// fully gated (unlike the alarm cap, there is no free allowance) —
|
||||
// `crearRangoVacaciones` is the authoritative choke point.
|
||||
final creada = await estado.crearRangoVacaciones(rango);
|
||||
if (!creada) {
|
||||
if (mounted) await mostrarHojaPremium(context);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (mounted) Navigator.pop(context);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user