manage_iap_subscriptions 0.2.0
manage_iap_subscriptions: ^0.2.0 copied to clipboard
Opens App Store or Google Play subscription management from Flutter on iOS and Android.
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 either store's subscription management UI.
class ManageIapSubscriptionsExample extends StatelessWidget {
/// Creates the plugin example application.
const ManageIapSubscriptionsExample({super.key});
Future<void> _showSubscriptionManagement(
BuildContext context,
Future<void> Function() showManagement,
) async {
try {
await showManagement();
} 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(
'Choose which store should manage the subscription.',
textAlign: TextAlign.center,
),
const SizedBox(height: 24),
FilledButton(
onPressed: () => _showSubscriptionManagement(
context,
showAppStoreSubscriptionManagement,
),
child: const Text('Manage App Store subscriptions'),
),
const SizedBox(height: 12),
FilledButton(
onPressed: () => _showSubscriptionManagement(
context,
showGooglePlaySubscriptionManagement,
),
child: const Text('Manage Google Play subscriptions'),
),
],
),
),
),
),
),
);
}
}