flutter-in-app-purchaselisted
Install: claude install-skill noory-code/noory-ai
# Flutter In-App Purchase
In-app purchases on the App Store and Play Store. Supports subscriptions, consumables, and non-consumables.
---
## Installation
```bash
flutter pub add in_app_purchase
```
## Prerequisites
- App Store Connect: register in-app products and complete agreements
- Google Play Console: register in-app products and configure the license key
---
## Quick Reference
### Initialization
```dart
import 'package:in_app_purchase/in_app_purchase.dart';
class IAPService {
final _iap = InAppPurchase.instance;
late StreamSubscription<List<PurchaseDetails>> _subscription;
Future<void> init() async {
final available = await _iap.isAvailable();
if (!available) return;
// listen to the purchase stream
_subscription = _iap.purchaseStream.listen(
_handlePurchaseUpdates,
onError: (error) => print('Purchase error: $error'),
);
// restore any incomplete purchases
await _iap.restorePurchases();
}
void dispose() {
_subscription.cancel();
}
}
```
### Load Products
```dart
Future<List<ProductDetails>> loadProducts() async {
const productIds = {'premium_monthly', 'premium_yearly', 'coins_100'};
final response = await _iap.queryProductDetails(productIds);
if (response.notFoundIDs.isNotEmpty) {
print('Products not found: ${response.notFoundIDs}');
}
return response.productDetails;
}
```
### Initiate a Purchase
```dart
Future<void> buyProduct(ProductDetails product) async {
final purchaseParam