encore_flutter 1.0.8 copy "encore_flutter: ^1.0.8" to clipboard
encore_flutter: ^1.0.8 copied to clipboard

Flutter plugin wrapping the native Encore iOS and Android SDKs for monetization, offers, and entitlements. All offer UI is rendered natively via StoreKit (iOS) and Play Billing (Android).

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:encore_flutter/encore_flutter.dart';
import 'package:purchases_flutter/purchases_flutter.dart' hide LogLevel;

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(const ExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Encore Flutter Example',
      theme: ThemeData(
        colorSchemeSeed: Colors.deepPurple,
        useMaterial3: true,
      ),
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String _status = 'Not configured';

  @override
  void initState() {
    super.initState();
    _initEncore();
  }

  Future<void> _initEncore() async {
    await Purchases.configure(
      PurchasesConfiguration('YOUR_REVENUECAT_API_KEY'),
    );

    await Encore.shared.configure(
      apiKey: 'YOUR_API_KEY',
      logLevel: LogLevel.debug,
    );

    Encore.shared.onPurchaseRequest((purchaseRequest) async {
      await Purchases.purchaseProduct(purchaseRequest.productId);
    });

    Encore.shared.onPassthrough((placementId) {
      debugPrint('Passthrough for placement: $placementId');
    });

    await Encore.shared.identify(
      userId: 'example_user_123',
      attributes: const UserAttributes(
        email: 'user@example.com',
        subscriptionTier: 'premium',
      ),
    );

    setState(() => _status = 'Configured & identified');
  }

  Future<void> _showOffer() async {
    setState(() => _status = 'Presenting offer...');
    final result = await Encore.shared.placement('example_placement').show();

    final message = switch (result) {
      PresentationResultGranted() => 'Offer granted!',
      PresentationResultNotGranted(:final reason) => 'Not granted: $reason',
    };

    if (mounted) setState(() => _status = message);
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('Encore Flutter Example')),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Text(_status, style: Theme.of(context).textTheme.titleMedium),
            const SizedBox(height: 24),
            FilledButton(
              onPressed: _showOffer,
              child: const Text('Show Offer'),
            ),
          ],
        ),
      ),
    );
  }
}
0
likes
0
points
328
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter plugin wrapping the native Encore iOS and Android SDKs for monetization, offers, and entitlements. All offer UI is rendered natively via StoreKit (iOS) and Play Billing (Android).

Homepage
Repository (GitHub)
View/report issues

Topics

#monetization #in-app-purchase #subscriptions #offers

License

unknown (license)

Dependencies

flutter, purchases_flutter

More

Packages that depend on encore_flutter

Packages that implement encore_flutter