vie_revenue_cat 1.0.0 copy "vie_revenue_cat: ^1.0.0" to clipboard
vie_revenue_cat: ^1.0.0 copied to clipboard

A production-grade, highly extensible RevenueCat & Hybrid In-App Purchase Manager for Flutter. Effortlessly handles Native RevenueCat Paywalls (purchases_ui_flutter), custom local Flutter paywalls, dy [...]

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:vie_revenue_cat/vie_revenue_cat.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  // 1. Register RevenueCatManager singleton
  Get.put(RevenueCatManager());

  // 2. Initialize RevenueCat with your Configuration and Callbacks
  await RevenueCatManager.instance.init(
    config: const RevenueCatConfig(
      appleApiKey: 'appl_YOUR_APPLE_API_KEY',
      googleApiKey: 'goog_YOUR_GOOGLE_API_KEY',
      entitlementId: 'pro',
      logLevel: LogLevel.debug,
    ),

    // Dynamic Remote Config Route Resolver (simulated here)
    remoteConfigResolver: (screenContext) {
      if (screenContext == 'home') return 'rc'; // RevenueCat Native UI
      if (screenContext == 'special_promo') return 'rc:black_friday_2026';
      if (screenContext == 'tools') return '5'; // Local Flutter Panel 5
      return 'rc';
    },

    // Local Flutter Paywall Builder
    localPaywallBuilder: (routeKey) {
      return LocalPaywallDialog(panelId: routeKey);
    },

    // Pro Status Listener
    onProStatusChanged: (isPro) {
      debugPrint('[Example App] Pro status changed: $isPro');
    },
  );

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return GetMaterialApp(
      title: 'Vie RevenueCat Example',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: const Color(0xFF6366F1)),
        useMaterial3: true,
      ),
      home: const HomeScreen(),
    );
  }
}

class HomeScreen extends StatelessWidget {
  const HomeScreen({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Vie RevenueCat Demo'),
        actions: const [
          // 1. Reactive Pro Badge in App Bar
          Center(
            child: Padding(
              padding: EdgeInsets.only(right: 16),
              child: ProBadge(label: 'PRO VIP'),
            ),
          ),
        ],
      ),
      body: SingleChildScrollView(
        padding: const EdgeInsets.all(20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            // 2. Reactive Premium Status Banner
            PremiumBuilder(
              proBuilder: (context) => Card(
                color: Colors.green.shade50,
                child: const Padding(
                  padding: EdgeInsets.all(16),
                  child: Row(
                    children: [
                      Icon(Icons.verified, color: Colors.green),
                      SizedBox(width: 12),
                      Text(
                        'Pro Active: All Features Unlocked!',
                        style: TextStyle(
                          fontWeight: FontWeight.bold,
                          color: Colors.green,
                        ),
                      ),
                    ],
                  ),
                ),
              ),
              freeBuilder: (context) => Card(
                color: Colors.amber.shade50,
                child: const Padding(
                  padding: EdgeInsets.all(16),
                  child: Row(
                    children: [
                      Icon(Icons.workspace_premium, color: Colors.amber),
                      SizedBox(width: 12),
                      Text(
                        'Free Plan: Upgrade for Pro features',
                        style: TextStyle(fontWeight: FontWeight.bold),
                      ),
                    ],
                  ),
                ),
              ),
            ),
            const SizedBox(height: 24),

            const Text(
              'Paywall Triggers (Hybrid Remote Config Routing):',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
            ),
            const SizedBox(height: 12),

            // Trigger RevenueCat Native Paywall (Home Context -> 'rc')
            ElevatedButton.icon(
              icon: const Icon(Icons.stars_rounded),
              label: const Text('Open RevenueCat Native Paywall (Home Context)'),
              onPressed: () {
                RevenueCatManager.instance.showPaywall(screenContext: 'home');
              },
            ),
            const SizedBox(height: 12),

            // Trigger Local Custom Flutter Paywall (Tools Context -> '5')
            OutlinedButton.icon(
              icon: const Icon(Icons.view_quilt_rounded),
              label: const Text('Open Local Flutter Panel (Tools Context -> 5)'),
              onPressed: () {
                RevenueCatManager.instance.showPaywall(screenContext: 'tools');
              },
            ),
            const SizedBox(height: 24),

            const Text(
              'Feature Gating Examples:',
              style: TextStyle(fontWeight: FontWeight.bold, fontSize: 16),
            ),
            const SizedBox(height: 12),

            // 3. PremiumGate wrapper demo
            ProGateWrapper(
              showLockOverlay: true,
              screenContext: 'home',
              onTap: () {
                Get.snackbar('Feature Used', 'Executing Pro AI feature...');
              },
              child: Container(
                height: 80,
                decoration: BoxDecoration(
                  color: Colors.deepPurple.shade100,
                  borderRadius: BorderRadius.circular(12),
                ),
                child: const Center(
                  child: Text(
                    'Exclusive Pro AI Feature (Click Me)',
                    style: TextStyle(
                      fontWeight: FontWeight.bold,
                      color: Colors.deepPurple,
                    ),
                  ),
                ),
              ),
            ),
            const SizedBox(height: 24),

            // 4. Restore Purchases Button
            ElevatedButton(
              style: ElevatedButton.styleFrom(
                backgroundColor: Colors.grey.shade200,
                foregroundColor: Colors.black87,
              ),
              onPressed: () => RevenueCatManager.instance.restorePurchases(),
              child: const Text('Restore Purchases'),
            ),
          ],
        ),
      ),
    );
  }
}

/// Simulated Local Flutter Paywall
class LocalPaywallDialog extends StatelessWidget {
  final String panelId;

  const LocalPaywallDialog({super.key, required this.panelId});

  @override
  Widget build(BuildContext context) {
    return Dialog(
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
      child: Padding(
        padding: const EdgeInsets.all(24),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              'Custom Local Paywall (Panel $panelId)',
              style: const TextStyle(fontSize: 18, fontWeight: FontWeight.bold),
            ),
            const SizedBox(height: 12),
            const Text(
              'This is your custom built-in Flutter paywall panel triggered dynamically via Remote Config.',
              textAlign: TextAlign.center,
            ),
            const SizedBox(height: 20),
            ElevatedButton(
              onPressed: () {
                // Simulate local subscription unlock
                RevenueCatManager.instance.isPro.value = true;
                Get.back();
              },
              child: const Text('Simulate Unlock'),
            ),
            TextButton(
              onPressed: () => Get.back(),
              child: const Text('Close'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
140
points
72
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A production-grade, highly extensible RevenueCat & Hybrid In-App Purchase Manager for Flutter. Effortlessly handles Native RevenueCat Paywalls (purchases_ui_flutter), custom local Flutter paywalls, dynamic Firebase Remote Config routing, reactive entitlement state management, and seamless feature gating.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

flutter, get, purchases_flutter, purchases_ui_flutter

More

Packages that depend on vie_revenue_cat