import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import '../providers/providers.dart'; import '../services/purchase_service.dart'; import '../theme/app_theme.dart'; class PaywallScreen extends ConsumerStatefulWidget { const PaywallScreen({super.key}); @override ConsumerState createState() => _PaywallScreenState(); } class _PaywallScreenState extends ConsumerState { bool _loading = false; @override void initState() { super.initState(); PurchaseService.instance.addListener(_onChange); } @override void dispose() { PurchaseService.instance.removeListener(_onChange); super.dispose(); } void _onChange() { if (!mounted) return; setState(() => _loading = PurchaseService.instance.isLoading); if (PurchaseService.instance.isPro && mounted) { Navigator.of(context).pop(); } } Future _buy() async { setState(() => _loading = true); await PurchaseService.instance.purchaseFullAccess(); } Future _restore() async { setState(() => _loading = true); await PurchaseService.instance.restorePurchases(); } @override Widget build(BuildContext context) { final isPro = ref.watch(isProProvider); return Scaffold( backgroundColor: AppColors.darkBg, appBar: AppBar( backgroundColor: Colors.transparent, elevation: 0, leading: IconButton( icon: const Icon(Icons.close, color: Colors.white70), onPressed: () => Navigator.of(context).pop(), ), ), body: SafeArea( child: SingleChildScrollView( padding: const EdgeInsets.fromLTRB(24, 0, 24, 24), child: Column( crossAxisAlignment: CrossAxisAlignment.stretch, children: [ const SizedBox(height: 16), Center( child: Container( width: 96, height: 96, decoration: BoxDecoration( gradient: const LinearGradient( colors: [Color(0xFF4A9EFF), Color(0xFF2D6BB5)], begin: Alignment.topLeft, end: Alignment.bottomRight, ), borderRadius: BorderRadius.circular(28), boxShadow: [ BoxShadow( color: AppColors.accent.withAlpha(80), blurRadius: 30, spreadRadius: 2, ), ], ), child: const Icon(Icons.workspace_premium, size: 56, color: Colors.white), ), ), const SizedBox(height: 28), const Center( child: Text( 'PAILot Pro', style: TextStyle( fontSize: 32, fontWeight: FontWeight.bold, color: Colors.white, ), ), ), const SizedBox(height: 8), const Center( child: Text( 'Unlock the full PAILot experience', style: TextStyle(fontSize: 15, color: Colors.white70), ), ), const SizedBox(height: 32), _FeatureRow( icon: Icons.all_inclusive, title: 'Unlimited sessions', body: 'Track every Claude Code session at once — no cap.', ), _FeatureRow( icon: Icons.history, title: 'Full message history', body: 'Keep every message on your phone, forever.', ), _FeatureRow( icon: Icons.flash_on, title: 'Priority push notifications', body: 'First-class APNs delivery for time-critical sessions.', ), _FeatureRow( icon: Icons.favorite, title: 'Support development', body: 'One-time purchase. No subscription. No tracking.', ), const SizedBox(height: 24), Container( padding: const EdgeInsets.all(16), decoration: BoxDecoration( color: AppColors.darkCard, borderRadius: BorderRadius.circular(16), border: Border.all( color: AppColors.accent.withAlpha(120), width: 1.5, ), ), child: const Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( 'One-time purchase', style: TextStyle( color: Colors.white70, fontSize: 13, ), ), SizedBox(height: 2), Text( 'Lifetime full access', style: TextStyle( color: Colors.white, fontSize: 17, fontWeight: FontWeight.w600, ), ), ], ), ), Text( '\$4.99', style: TextStyle( color: AppColors.accent, fontSize: 28, fontWeight: FontWeight.bold, ), ), ], ), ), const SizedBox(height: 20), SizedBox( height: 54, child: ElevatedButton( onPressed: (_loading || isPro) ? null : _buy, style: ElevatedButton.styleFrom( backgroundColor: AppColors.accent, foregroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(14), ), ), child: _loading ? const SizedBox( width: 22, height: 22, child: CircularProgressIndicator( color: Colors.white, strokeWidth: 2.5, ), ) : Text( isPro ? 'You’re already Pro' : 'Unlock PAILot Pro', style: const TextStyle( fontSize: 17, fontWeight: FontWeight.w600, ), ), ), ), const SizedBox(height: 12), TextButton( onPressed: _loading ? null : _restore, child: const Text( 'Restore previous purchase', style: TextStyle(color: Colors.white70), ), ), const SizedBox(height: 16), const Center( child: Text( 'Payment processed by Apple. No subscription, no auto-renew.', textAlign: TextAlign.center, style: TextStyle(color: Colors.white38, fontSize: 11), ), ), ], ), ), ), ); } } class _FeatureRow extends StatelessWidget { final IconData icon; final String title; final String body; const _FeatureRow({ required this.icon, required this.title, required this.body, }); @override Widget build(BuildContext context) { return Padding( padding: const EdgeInsets.only(bottom: 18), child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 38, height: 38, decoration: BoxDecoration( color: AppColors.accent.withAlpha(40), borderRadius: BorderRadius.circular(10), ), child: Icon(icon, color: AppColors.accent, size: 20), ), const SizedBox(width: 14), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( title, style: const TextStyle( color: Colors.white, fontSize: 15, fontWeight: FontWeight.w600, ), ), const SizedBox(height: 2), Text( body, style: const TextStyle( color: Colors.white60, fontSize: 13, height: 1.35, ), ), ], ), ), ], ), ); } }