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:
+68
-22
@@ -4,11 +4,15 @@ import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'estado/estado_busqueda.dart';
|
||||
import 'estado/estado_ecualizador.dart';
|
||||
import 'estado/estado_entitlement.dart';
|
||||
import 'estado/estado_grabacion.dart';
|
||||
import 'estado/estado_radio.dart';
|
||||
import 'estado/estado_alarmas.dart';
|
||||
import 'estado/estado_idioma.dart';
|
||||
import 'estado/estado_navegacion.dart';
|
||||
import 'servicios/servicio_anuncios.dart';
|
||||
import 'servicios/servicio_compras.dart';
|
||||
import 'widgets/banner_anuncio_superior.dart';
|
||||
import 'l10n/display_names.dart';
|
||||
import 'l10n/gen/app_localizations.dart';
|
||||
import 'modelos/alarma_musical.dart';
|
||||
@@ -32,7 +36,7 @@ import 'servicios/servicio_alarmas_android.dart';
|
||||
import 'servicios/servicio_dispositivo_audio.dart';
|
||||
|
||||
class PluriWaveApp extends StatelessWidget {
|
||||
const PluriWaveApp({super.key, this.prefs, this.fuenteAuto});
|
||||
const PluriWaveApp({super.key, this.prefs, this.fuenteAuto, this.compras});
|
||||
|
||||
/// Single SharedPreferences instance resolved in main() (S3-R4) and
|
||||
/// injected into every state/service.
|
||||
@@ -44,16 +48,31 @@ class PluriWaveApp extends StatelessWidget {
|
||||
/// [PluriWaveApp] without it.
|
||||
final FuenteEmisorasAuto? fuenteAuto;
|
||||
|
||||
/// Purchase I/O port (iap-freemium-unlock, Design ADR-2). Optional and
|
||||
/// `null` by default — mirrors [fuenteAuto]'s injection shape, so every
|
||||
/// pre-existing test that constructs [PluriWaveApp] without it never
|
||||
/// touches the real `in_app_purchase` plugin channel. `main.dart` wires
|
||||
/// the real [ServicioComprasPlayBilling].
|
||||
final PuertoCompras? compras;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
// iap-freemium-unlock (Design ADR-3): registered FIRST so every
|
||||
// provider below can read it via `context.read` inside a lazy
|
||||
// `esPremium` closure — `MultiProvider` nests top-to-bottom, so only
|
||||
// a provider ABOVE a given one is reachable from its own `create`.
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => EstadoEntitlement(prefs: prefs, compras: compras),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create:
|
||||
(_) => EstadoRadio(
|
||||
(context) => EstadoRadio(
|
||||
prefs: prefs,
|
||||
dispositivoAudio: ServicioDispositivoAudioReal(),
|
||||
fuenteAuto: fuenteAuto,
|
||||
esPremium: () => context.read<EstadoEntitlement>().esPremium,
|
||||
),
|
||||
),
|
||||
// Domain notifiers (S4-R1/R2/R3). Created and disposed by EstadoRadio
|
||||
@@ -69,13 +88,28 @@ class PluriWaveApp extends StatelessWidget {
|
||||
ListenableProvider<EstadoBusqueda>(
|
||||
create: (context) => context.read<EstadoRadio>().busqueda,
|
||||
),
|
||||
ChangeNotifierProvider(create: (_) => EstadoAlarmas(prefs: prefs)),
|
||||
ChangeNotifierProvider(
|
||||
create:
|
||||
(context) => EstadoAlarmas(
|
||||
prefs: prefs,
|
||||
esPremium: () => context.read<EstadoEntitlement>().esPremium,
|
||||
),
|
||||
),
|
||||
ChangeNotifierProvider(
|
||||
create: (_) => EstadoIdioma(sharedPreferences: prefs),
|
||||
),
|
||||
// Design ADR-8: root-to-root navigation state. `_PaginaPrincipal`
|
||||
// watches this instead of owning `_indice` locally.
|
||||
ChangeNotifierProvider(create: (_) => EstadoNavegacionRaiz()),
|
||||
// iap-freemium-unlock (Design "Interfaces / Contracts", ADR-6): a
|
||||
// plain (non-notifier) `Provider` — session-scoped ad state, never
|
||||
// rebuilds the widget tree itself.
|
||||
Provider<ServicioAnuncios>(
|
||||
create:
|
||||
(context) => ServicioAnuncios(
|
||||
esPremium: () => context.read<EstadoEntitlement>().esPremium,
|
||||
),
|
||||
),
|
||||
],
|
||||
child: Consumer<EstadoIdioma>(
|
||||
builder:
|
||||
@@ -218,28 +252,40 @@ class _PaginaPrincipalState extends State<_PaginaPrincipal>
|
||||
final indice = navegacion.indice;
|
||||
|
||||
return PluriWaveScaffold(
|
||||
body: SafeArea(
|
||||
top: false,
|
||||
child: AnimatedSwitcher(
|
||||
duration: context.pluriMotion.normal,
|
||||
switchInCurve: Curves.easeOutCubic,
|
||||
switchOutCurve: Curves.easeInCubic,
|
||||
transitionBuilder:
|
||||
(child, animation) => FadeTransition(
|
||||
opacity: animation,
|
||||
child: SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0.035, 0),
|
||||
end: Offset.zero,
|
||||
).animate(animation),
|
||||
child: child,
|
||||
// ad-display spec "Persistent Top Banner, Never Overlapping Content"
|
||||
// (design.md ADR-6): a `Column` sibling, NEVER a `Stack`/overlay — the
|
||||
// banner RESERVES its own space above the existing body instead of
|
||||
// covering any of it. `BannerAnuncioSuperior` itself collapses to
|
||||
// `SizedBox.shrink()` (zero layout impact) for premium/unloaded.
|
||||
body: Column(
|
||||
children: [
|
||||
const SafeArea(bottom: false, child: BannerAnuncioSuperior()),
|
||||
Expanded(
|
||||
child: SafeArea(
|
||||
top: false,
|
||||
child: AnimatedSwitcher(
|
||||
duration: context.pluriMotion.normal,
|
||||
switchInCurve: Curves.easeOutCubic,
|
||||
switchOutCurve: Curves.easeInCubic,
|
||||
transitionBuilder:
|
||||
(child, animation) => FadeTransition(
|
||||
opacity: animation,
|
||||
child: SlideTransition(
|
||||
position: Tween<Offset>(
|
||||
begin: const Offset(0.035, 0),
|
||||
end: Offset.zero,
|
||||
).animate(animation),
|
||||
child: child,
|
||||
),
|
||||
),
|
||||
child: KeyedSubtree(
|
||||
key: ValueKey<int>(indice),
|
||||
child: _paginas[indice],
|
||||
),
|
||||
),
|
||||
child: KeyedSubtree(
|
||||
key: ValueKey<int>(indice),
|
||||
child: _paginas[indice],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
bottomNavigationBar: SafeArea(
|
||||
top: false,
|
||||
|
||||
Reference in New Issue
Block a user