manage_iap_subscriptions 0.1.0 copy "manage_iap_subscriptions: ^0.1.0" to clipboard
manage_iap_subscriptions: ^0.1.0 copied to clipboard

Opens the native App Store or Google Play subscription management UI from Flutter.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:manage_iap_subscriptions/manage_iap_subscriptions.dart';

void main() {
  runApp(const ManageIapSubscriptionsExample());
}

/// Demonstrates how to open the current store's subscription management UI.
class ManageIapSubscriptionsExample extends StatelessWidget {
  /// Creates the plugin example application.
  const ManageIapSubscriptionsExample({super.key});

  Future<void> _showManageSubscriptions(BuildContext context) async {
    try {
      await showManageSubscriptions();
    } on PlatformException catch (error) {
      if (!context.mounted) return;
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          content: Text(
            error.message ?? 'Subscription management could not be opened.',
          ),
        ),
      );
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
      ),
      home: Builder(
        builder: (context) => Scaffold(
          appBar: AppBar(title: const Text('manage_iap_subscriptions')),
          body: Center(
            child: Padding(
              padding: const EdgeInsets.all(24),
              child: Column(
                mainAxisSize: MainAxisSize.min,
                children: [
                  const Text(
                    'Open subscription management for the store associated '
                    'with this device.',
                    textAlign: TextAlign.center,
                  ),
                  const SizedBox(height: 24),
                  FilledButton(
                    onPressed: () => _showManageSubscriptions(context),
                    child: const Text('Show subscription management'),
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}