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:
@@ -0,0 +1,75 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/estado/estado_entitlement.dart';
|
||||
import 'package:pluriwave/servicios/servicio_anuncios.dart';
|
||||
import 'package:pluriwave/widgets/banner_anuncio_superior.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
/// Ad-display spec "Persistent Top Banner, Never Overlapping Content": the
|
||||
/// banner is entitlement-aware and reserves layout via a `Column`
|
||||
/// (`SizedBox.shrink()` collapses it to zero footprint) — never a `Stack`
|
||||
/// overlay. AdMob's own `BannerAd.load()` cannot reach a real ad server in
|
||||
/// `flutter test` (no plugin channel registered), so it always resolves to
|
||||
/// "unloaded" here — exactly the same degrade-to-shrink path a genuine
|
||||
/// failed load takes in production (never a crash, never a placeholder).
|
||||
void main() {
|
||||
setUp(() {
|
||||
SharedPreferences.setMockInitialValues({});
|
||||
});
|
||||
|
||||
Widget construir({required bool premium}) {
|
||||
return MultiProvider(
|
||||
providers: [
|
||||
ChangeNotifierProvider<EstadoEntitlement>(
|
||||
create: (_) {
|
||||
final estado = EstadoEntitlement(prefs: null);
|
||||
return estado;
|
||||
},
|
||||
),
|
||||
Provider<ServicioAnuncios>(
|
||||
create: (_) => ServicioAnuncios(esPremium: () => premium),
|
||||
),
|
||||
],
|
||||
child: MaterialApp(
|
||||
home: Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
const BannerAnuncioSuperior(),
|
||||
const Expanded(child: Center(child: Text('contenido'))),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
testWidgets(
|
||||
'usuario free sin anuncio cargado: colapsa a SizedBox.shrink (nunca overlay)',
|
||||
(tester) async {
|
||||
await tester.pumpWidget(construir(premium: false));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
|
||||
final banner = find.byType(BannerAnuncioSuperior);
|
||||
expect(banner, findsOneWidget);
|
||||
// Collapsed to zero footprint (no ad ever loads in a widget test — no
|
||||
// AdMob plugin channel registered) — a `SizedBox.shrink()`, not an
|
||||
// overlay: the Column layout below it stays fully visible.
|
||||
expect(tester.getSize(banner).height, 0);
|
||||
expect(find.text('contenido'), findsOneWidget);
|
||||
},
|
||||
);
|
||||
|
||||
testWidgets('usuario premium: nunca intenta mostrar el banner', (
|
||||
tester,
|
||||
) async {
|
||||
await tester.pumpWidget(construir(premium: true));
|
||||
await tester.pump();
|
||||
await tester.pump(const Duration(milliseconds: 50));
|
||||
|
||||
final banner = find.byType(BannerAnuncioSuperior);
|
||||
expect(tester.getSize(banner).height, 0);
|
||||
expect(find.text('contenido'), findsOneWidget);
|
||||
});
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
import 'package:pluriwave/estado/estado_alarmas.dart';
|
||||
import 'package:pluriwave/estado/estado_busqueda.dart';
|
||||
import 'package:pluriwave/estado/estado_ecualizador.dart';
|
||||
import 'package:pluriwave/estado/estado_entitlement.dart';
|
||||
import 'package:pluriwave/estado/estado_grabacion.dart';
|
||||
import 'package:pluriwave/estado/estado_idioma.dart';
|
||||
import 'package:pluriwave/estado/estado_radio.dart';
|
||||
@@ -213,6 +214,9 @@ void main() {
|
||||
),
|
||||
ListenableProvider<EstadoGrabacion>.value(value: estado.grabacion),
|
||||
ChangeNotifierProvider<EstadoIdioma>.value(value: estadoIdioma),
|
||||
ChangeNotifierProvider<EstadoEntitlement>(
|
||||
create: (_) => EstadoEntitlement(prefs: null),
|
||||
),
|
||||
],
|
||||
child: testApp(const PantallaAjustes()),
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user