requestProducts()
Fetches product or subscription information with unified API (v2.7.0+).
Overview
The requestProducts()
method fetches product information for the specified product IDs from the App Store (iOS) or Google Play Store (Android). This replaces the deprecated getProducts()
and getSubscriptions()
methods with a unified API that uses a type parameter to distinguish between regular products and subscriptions.
Signature
Future<List<IAPItem>> requestProducts({
required List<String> skus,
String type = 'inapp',
})
Parameters
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
skus | List<String> | Yes | - | List of product identifiers to fetch |
type | String | No | 'inapp' | Product type: 'inapp' for regular products or 'subs' for subscriptions |
Returns
- Type:
Future<List<IAPItem>>
- Description: A list of product items with pricing and metadata
Usage Examples
Fetch Regular Products
try {
List<IAPItem> products = await FlutterInappPurchase.instance.requestProducts(
skus: ['coins_100', 'coins_500', 'remove_ads'],
type: 'inapp',
);
for (var product in products) {
print('Product: ${product.title}');
print('Price: ${product.localizedPrice}');
print('Currency: ${product.currency}');
}
} catch (e) {
print('Failed to fetch products: $e');
}
Fetch Subscriptions
try {
List<IAPItem> subscriptions = await FlutterInappPurchase.instance.requestProducts(
skus: ['premium_monthly', 'premium_yearly'],
type: 'subs',
);
for (var subscription in subscriptions) {
print('Subscription: ${subscription.title}');
print('Price: ${subscription.localizedPrice}');
print('Description: ${subscription.description}');
}
} catch (e) {
print('Failed to fetch subscriptions: $e');
}
Combined Example
class ProductService {
Future<void> loadAllProducts() async {
try {
// Load regular products
final products = await FlutterInappPurchase.instance.requestProducts(
skus: ['coins_100', 'remove_ads'],
type: 'inapp',
);
// Load subscriptions
final subscriptions = await FlutterInappPurchase.instance.requestProducts(
skus: ['premium_monthly', 'premium_yearly'],
type: 'subs',
);
print('Loaded ${products.length} products');
print('Loaded ${subscriptions.length} subscriptions');
} catch (e) {
print('Error loading products: $e');
}
}
}
Product Types
'inapp' Type
- Consumables: Items that can be purchased multiple times (coins, gems)
- Non-consumables: Items purchased once and owned forever (remove ads, premium features)
'subs' Type
- Auto-renewable subscriptions: Recurring subscriptions with automatic renewal
- Non-renewing subscriptions: Fixed-duration subscriptions without auto-renewal
Error Handling
try {
final products = await FlutterInappPurchase.instance.requestProducts(
skus: productIds,
type: 'inapp',
);
if (products.isEmpty) {
print('No products found for the given SKUs');
}
} catch (e) {
if (e.toString().contains('E_NOT_PREPARED')) {
print('Store not initialized');
} else if (e.toString().contains('E_NETWORK')) {
print('Network error - check internet connection');
} else {
print('Unknown error: $e');
}
}
Platform Differences
iOS
- Products must be configured in App Store Connect
- Products must be in "Ready to Submit" or "Approved" status
- Bundle ID must match exactly
Android
- Products must be active in Google Play Console
- App must be uploaded to at least Internal Testing
- Package name must match exactly
Migration from Old API
Before (Deprecated)
// Old separate methods
final products = await FlutterInappPurchase.instance.getProducts(productIds);
final subscriptions = await FlutterInappPurchase.instance.getSubscriptions(subscriptionIds);
After (Recommended)
// New unified method
final products = await FlutterInappPurchase.instance.requestProducts(
skus: productIds,
type: 'inapp',
);
final subscriptions = await FlutterInappPurchase.instance.requestProducts(
skus: subscriptionIds,
type: 'subs',
);
Best Practices
- Cache Results: Store product information to reduce API calls
- Handle Empty Results: Always check if the returned list is empty
- Error Recovery: Implement retry logic for network failures
- Type Safety: Use the correct type parameter for your products
- SKU Validation: Ensure SKUs match exactly with store configuration
Related Methods
requestPurchase()
- Request a product purchaserequestSubscription()
- Request a subscription purchasegetAvailablePurchases()
- Get user's current purchases
See Also
- Products Guide - Detailed product implementation guide
- Subscriptions Guide - Subscription-specific implementation
- Troubleshooting - Common issues and solutions