Files
pluriwave/lib/widgets/hoja_premium.dart
T
FreeTLab aa0b242374 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.
2026-08-10 20:37:07 +02:00

106 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../estado/estado_entitlement.dart';
import '../l10n/gen/app_localizations.dart';
import '../tema/pluriwave_tokens.dart';
import 'pluri_glass_surface.dart';
import 'pluri_layout.dart';
/// Reusable paywall sheet (Design "File Changes" — `hoja_premium.dart`),
/// opened from every gated entry point plus the Settings premium row
/// (freemium-gating spec "Purchase Entry Points At Every Gate Plus
/// Settings"). Mirrors `FormularioEmisoraPersonalizada`'s bottom-sheet
/// shape (`ajustes_emisoras_personalizadas.dart`).
Future<void> mostrarHojaPremium(BuildContext context) {
return showModalBottomSheet<void>(
context: context,
isScrollControlled: true,
useSafeArea: true,
backgroundColor: Colors.transparent,
builder: (_) => const HojaPremium(),
);
}
class HojaPremium extends StatelessWidget {
const HojaPremium({super.key});
@override
Widget build(BuildContext context) {
final l10n = AppLocalizations.of(context);
final entitlement = context.watch<EstadoEntitlement>();
final bottom = MediaQuery.of(context).viewInsets.bottom;
return Padding(
padding: EdgeInsets.fromLTRB(
PluriLayout.horizontal,
PluriLayout.horizontal,
PluriLayout.horizontal,
PluriLayout.horizontal + bottom,
),
child: PluriGlassSurface(
padding: const EdgeInsets.all(24),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
Icon(
Icons.workspace_premium_rounded,
color: PluriWaveTokens.brand,
),
const SizedBox(width: 10),
Expanded(
child: Text(
l10n.funcionPremium,
style: Theme.of(context).textTheme.titleLarge?.copyWith(
fontWeight: FontWeight.w900,
),
),
),
],
),
const SizedBox(height: 20),
if (entitlement.esPremium)
Padding(
key: const ValueKey('hoja-premium-activo'),
padding: const EdgeInsets.only(bottom: 12),
child: Text(
l10n.equalizerActive,
style: Theme.of(context).textTheme.bodyMedium,
),
)
else
FilledButton.icon(
key: const ValueKey('hoja-premium-comprar'),
onPressed:
entitlement.compraEnCurso
? null
: () => entitlement.comprar(),
icon:
entitlement.compraEnCurso
? const SizedBox(
width: 18,
height: 18,
child: CircularProgressIndicator(strokeWidth: 2),
)
: const Icon(Icons.lock_open_rounded),
label: Text(l10n.desbloquearPremium),
),
const SizedBox(height: 10),
OutlinedButton(
key: const ValueKey('hoja-premium-restaurar'),
onPressed:
entitlement.compraEnCurso
? null
: () => entitlement.restaurar(),
child: Text(l10n.restaurarCompras),
),
],
),
),
);
}
}