Installation & Setup
Learn how to install and configure flutter_inapp_purchase in your Flutter project.
Prerequisites
Before installing flutter_inapp_purchase, ensure you have:
- Flutter SDK 2.0.0 or higher
- Dart SDK 2.12.0 or higher
- Active Apple Developer account (for iOS)
- Active Google Play Developer account (for Android)
- Physical device for testing (simulators/emulators have limited support)
Package Installation
Add flutter_inapp_purchase to your project:
flutter pub add flutter_inapp_purchase
Or add it manually to your pubspec.yaml:
dependencies:
flutter_inapp_purchase: ^7.0.0
Then run:
flutter pub get
Platform Configuration
iOS Configuration
Enable In-App Purchase Capability
- Open your project in Xcode
- Select your project in the navigator
- Select your target
- Go to Signing & Capabilities tab
- Click + Capability and add In-App Purchase
Configure Info.plist (iOS 14+)
Add the following to your ios/Runner/Info.plist:
<key>LSApplicationQueriesSchemes</key>
<array>
<string>itms-apps</string>
</array>
StoreKit Configuration (Optional)
For testing with StoreKit 2, create a .storekit configuration file:
- In Xcode, go to File → New → File
- Choose StoreKit Configuration File
- Add your products for testing
Android Configuration
Update build.gradle
Ensure your android/app/build.gradle has the minimum SDK version and platform configuration:
For Groovy (build.gradle):
android {
compileSdkVersion 34
defaultConfig {
minSdkVersion 21 // Required minimum
targetSdkVersion 34
// Required for v7.1.14+: Select Google Play platform
missingDimensionStrategy 'platform', 'play'
}
}
For Kotlin DSL (build.gradle.kts):
android {
compileSdkVersion(34)
defaultConfig {
minSdkVersion(21) // Required minimum
targetSdkVersion(34)
// Required for v7.1.14+: Select Google Play platform
missingDimensionStrategy("platform", "play")
}
}
The missingDimensionStrategy configuration is required since v7.1.14 due to product flavor support for Meta Horizon OS. For Meta Quest support, see the Horizon OS Setup Guide.
Enable ProGuard Rules (if using ProGuard)
Add to your android/app/proguard-rules.pro:
# In-App Purchase
-keep class com.amazon.** {*;}
-keep class dev.hyo.** { *; }
-keep class com.android.vending.billing.**
-dontwarn com.amazon.**
-keepattributes *Annotation*
Permissions
The plugin automatically adds the required billing permission to your manifest.
Configuration
App Store Connect (iOS)
-
Sign in to App Store Connect
-
Select your app
-
Navigate to Monetization → In-App Purchases
-
Create your products:
- Consumable: Can be purchased multiple times
- Non-Consumable: One-time purchase
- Auto-Renewable Subscription: Recurring payments
- Non-Renewing Subscription: Fixed duration
-
Fill in required fields:
- Reference Name (internal use)
- Product ID (used in code)
- Pricing
- Localizations
-
Submit for review with your app
Google Play Console (Android)
-
Sign in to Google Play Console
-
Select your app
-
Navigate to Monetization → In-app products
-
Create products:
- One-time products: Consumable or non-consumable
- Subscriptions: Recurring payments
-
Configure product details:
- Product ID (used in code)
- Name and description
- Price
- Status (Active)
-
Save and activate products
Verification
Initialize the Plugin
You have two options for managing IAP instances:
Option 1: Create Your Own Instance
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
class MyApp extends StatefulWidget {
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
final FlutterInappPurchase iap = FlutterInappPurchase();
void initState() {
super.initState();
_initializeIAP();
}
Future<void> _initializeIAP() async {
try {
await iap.initConnection();
print('IAP connection initialized successfully');
} catch (e) {
print('Failed to initialize IAP connection: $e');
}
}
void dispose() {
iap.endConnection();
super.dispose();
}
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
Option 2: Use Singleton Instance
class _MyAppState extends State<MyApp> {
final iap = FlutterInappPurchase.instance;
Future<void> _initializeIAP() async {
await iap.initConnection();
}
}
Test Connection
Test your setup with this verification code:
Future<void> _testConnection() async {
final iap = FlutterInappPurchase(); // or FlutterInappPurchase.instance
try {
final bool connected = await iap.initConnection();
print('Connection result: $connected');
// Test product fetching
final result = await iap.fetchProducts(
skus: ['test_product_id'],
type: ProductQueryType.InApp,
);
print('Found ${result.value.length} products');
} catch (e) {
print('Connection test failed: $e');
}
}
Next Steps
Now that you have flutter_inapp_purchase installed and configured:
- Basic Setup Guide - Learn the fundamentals
- Platform Specific Setup - Android specific configuration
- Platform Specific Setup - iOS specific configuration
Troubleshooting
iOS Common Issues
Permission Denied
- Ensure In-App Purchase capability is enabled
- Verify your Apple Developer account has active agreements
- Check that products are configured in App Store Connect
Products Not Loading
- Products must be submitted for review (at least once)
- Wait 24 hours after creating products
- Verify product IDs match exactly
Android Common Issues
Billing Unavailable
- Test on a real device (not emulator)
- Ensure Google Play is installed and up-to-date
- Verify app is signed with the same key as uploaded to Play Console
Products Not Found
- Products must be active in Play Console
- App must be published (at least to internal testing)
- Wait 2-3 hours after creating products
Need help? Check our migration guide or open an issue on GitHub.
