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: ^6.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:
android {
compileSdkVersion 34
defaultConfig {
minSdkVersion 21 // Required minimum
targetSdkVersion 34
}
}
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
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
class MyApp extends StatefulWidget {
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
void initState() {
super.initState();
_initializeIAP();
}
Future<void> _initializeIAP() async {
try {
await FlutterInappPurchase.instance.initConnection();
print('IAP connection initialized successfully');
} catch (e) {
print('Failed to initialize IAP connection: $e');
}
}
void dispose() {
FlutterInappPurchase.instance.endConnection();
super.dispose();
}
Widget build(BuildContext context) {
return MaterialApp(
home: MyHomePage(),
);
}
}
Test Connection
Test your setup with this verification code:
Future<void> _testConnection() async {
try {
final String? result = await FlutterInappPurchase.instance.initConnection();
print('Connection result: $result');
// Test product fetching
final products = await FlutterInappPurchase.instance.getProducts(['test_product_id']);
print('Found ${products.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.