Skip to content

Commit 255820b

Browse files
authored
refactor: clean up deprecated APIs for v6.1.0 (#521)
## Changes - Renamed `getAvailablePurchases()` to `getActivePurchases()` for clarity - Renamed `getPurchaseHistory()` to `getPurchaseHistories()` for consistency - Removed all deprecated methods marked for removal in v6.0.0 - Cleaned up legacy code and unused methods - Updated example code to use new APIs ## Breaking Changes - `getAvailablePurchases()` → `getActivePurchases()` - Removed deprecated methods: `initialize()`, `checkSubscribed()`, `getAvailablePurchasesAsync()`, etc. ## Migration Guide - Replace `getAvailablePurchases()` with `getActivePurchases()` - Replace `getPurchaseHistory()` with `getPurchaseHistories()` - Use `initConnection()` instead of `initialize()` - Use `finishTransaction()` instead of deprecated platform-specific methods
1 parent 1ed708f commit 255820b

File tree

8 files changed

+112
-487
lines changed

8 files changed

+112
-487
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# This podspec is NOT to be published. It is only used as a local source!
3+
# This is a generated file; do not edit or check into version control.
4+
#
5+
6+
Pod::Spec.new do |s|
7+
s.name = 'Flutter'
8+
s.version = '1.0.0'
9+
s.summary = 'A UI toolkit for beautiful and fast apps.'
10+
s.homepage = 'https://flutter.dev'
11+
s.license = { :type => 'BSD' }
12+
s.author = { 'Flutter Dev Team' => '[email protected]' }
13+
s.source = { :git => 'https://github.com/flutter/engine', :tag => s.version.to_s }
14+
s.ios.deployment_target = '13.0'
15+
# Framework linking is handled by Flutter tooling, not CocoaPods.
16+
# Add a placeholder to satisfy `s.dependency 'Flutter'` plugin podspecs.
17+
s.vendored_frameworks = 'path/to/nothing'
18+
end

example/lib/src/screens/available_purchases_screen.dart

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import 'dart:async';
2-
import 'dart:io' show Platform;
32
import 'package:flutter/material.dart';
43
import 'package:flutter/cupertino.dart';
54
import 'package:flutter_inapp_purchase/flutter_inapp_purchase.dart';
@@ -16,7 +15,7 @@ class _AvailablePurchasesScreenState extends State<AvailablePurchasesScreen> {
1615
final FlutterInappPurchase _iap = FlutterInappPurchase.instance;
1716

1817
List<Purchase> _availablePurchases = [];
19-
List<PurchasedItem> _purchaseHistory = [];
18+
List<Purchase> _purchaseHistory = [];
2019
bool _loading = false;
2120
bool _connected = false;
2221
String? _error;
@@ -67,14 +66,14 @@ class _AvailablePurchasesScreenState extends State<AvailablePurchasesScreen> {
6766

6867
try {
6968
// Load available purchases (non-consumed)
70-
final availablePurchases = await _iap.getAvailablePurchases();
69+
final availablePurchases = await _iap.getActivePurchases();
7170

7271
// Load purchase history
73-
final purchaseHistory = await _iap.getPurchaseHistory();
72+
final purchaseHistory = await _iap.getPurchaseHistories();
7473

7574
setState(() {
7675
_availablePurchases = availablePurchases;
77-
_purchaseHistory = purchaseHistory ?? [];
76+
_purchaseHistory = purchaseHistory;
7877
});
7978
} catch (e) {
8079
setState(() {
@@ -95,7 +94,7 @@ class _AvailablePurchasesScreenState extends State<AvailablePurchasesScreen> {
9594
});
9695

9796
try {
98-
final restored = await _iap.getAvailablePurchases();
97+
final restored = await _iap.getActivePurchases();
9998
setState(() {
10099
_availablePurchases = restored;
101100
});
@@ -208,7 +207,7 @@ class _AvailablePurchasesScreenState extends State<AvailablePurchasesScreen> {
208207
);
209208
}
210209

211-
Widget _buildPurchaseHistoryItem(PurchasedItem item) {
210+
Widget _buildPurchaseHistoryItem(Purchase item) {
212211
return Card(
213212
margin: const EdgeInsets.only(bottom: 8),
214213
child: Padding(
@@ -221,7 +220,7 @@ class _AvailablePurchasesScreenState extends State<AvailablePurchasesScreen> {
221220
children: [
222221
Expanded(
223222
child: Text(
224-
item.productId ?? 'Unknown Product',
223+
item.productId.isEmpty ? 'Unknown Product' : item.productId,
225224
style: const TextStyle(
226225
fontSize: 16,
227226
fontWeight: FontWeight.w600,

example/lib/src/screens/debug_purchases_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class _DebugPurchasesScreenState extends State<DebugPurchasesScreen> {
3636
await Future<void>.delayed(const Duration(seconds: 1));
3737

3838
// Get all available purchases
39-
final purchases = await _iap.getAvailablePurchases();
39+
final purchases = await _iap.getActivePurchases();
4040

4141
setState(() {
4242
_purchases = purchases;

example/lib/src/screens/subscription_flow_screen.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ class _SubscriptionFlowScreenState extends State<SubscriptionFlowScreen> {
2626
bool _isConnecting = true;
2727
bool _isLoadingProducts = false;
2828
String? _purchaseResult;
29-
String? _initError;
30-
Purchase? _currentPurchase;
3129
StreamSubscription<Purchase>? _purchaseUpdatedSubscription;
3230
StreamSubscription<PurchaseError>? _purchaseErrorSubscription;
3331

@@ -58,9 +56,7 @@ class _SubscriptionFlowScreenState extends State<SubscriptionFlowScreen> {
5856
});
5957

6058
if (!_connected) {
61-
setState(() {
62-
_initError = 'Failed to connect to store';
63-
});
59+
debugPrint('Failed to connect to store');
6460
return;
6561
}
6662

@@ -102,7 +98,7 @@ class _SubscriptionFlowScreenState extends State<SubscriptionFlowScreen> {
10298
debugPrint('TransactionId: ${purchase.transactionId}');
10399
_handlePurchaseUpdate(purchase);
104100
},
105-
onError: (error) {
101+
onError: (Object error) {
106102
debugPrint('❌ Subscription stream error: $error');
107103
},
108104
);
@@ -125,7 +121,6 @@ class _SubscriptionFlowScreenState extends State<SubscriptionFlowScreen> {
125121

126122
setState(() {
127123
_isProcessing = false;
128-
_currentPurchase = purchase;
129124

130125
// Format subscription result like KMP-IAP
131126
_purchaseResult = '''
@@ -195,7 +190,7 @@ Platform: ${error.platform}
195190

196191
Future<void> _loadActiveSubscriptions() async {
197192
try {
198-
final purchases = await _iap.getAvailablePurchases();
193+
final purchases = await _iap.getActivePurchases();
199194
setState(() {
200195
_activeSubscriptions = purchases
201196
.where((p) => subscriptionIds.contains(p.productId))
@@ -503,7 +498,6 @@ Platform: ${error.platform}
503498
onPressed: () {
504499
setState(() {
505500
_purchaseResult = null;
506-
_currentPurchase = null;
507501
});
508502
},
509503
),

0 commit comments

Comments
 (0)