Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 612078d

Browse files
author
Chris Yang
committed
review
1 parent 63b9fe8 commit 612078d

19 files changed

+211
-186
lines changed

packages/in_app_purchase/CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 0.4.0-nullsafety.0
1+
## 0.4.0
22

33
* Migrate to nullsafety.
44
* Deprecate `sandboxTesting`, introduce `simulatesAskToBuyInSandbox`.

packages/in_app_purchase/example/lib/main.dart

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
// @dart = 2.10
65
import 'dart:async';
76
import 'dart:io';
87
import 'package:flutter/material.dart';
@@ -33,19 +32,19 @@ class _MyApp extends StatefulWidget {
3332

3433
class _MyAppState extends State<_MyApp> {
3534
final InAppPurchaseConnection _connection = InAppPurchaseConnection.instance;
36-
StreamSubscription<List<PurchaseDetails>> _subscription;
35+
late StreamSubscription<List<PurchaseDetails>> _subscription;
3736
List<String> _notFoundIds = [];
3837
List<ProductDetails> _products = [];
3938
List<PurchaseDetails> _purchases = [];
4039
List<String> _consumables = [];
4140
bool _isAvailable = false;
4241
bool _purchasePending = false;
4342
bool _loading = true;
44-
String _queryProductError;
43+
String? _queryProductError;
4544

4645
@override
4746
void initState() {
48-
Stream purchaseUpdated =
47+
final Stream<List<PurchaseDetails>> purchaseUpdated =
4948
InAppPurchaseConnection.instance.purchaseUpdatedStream;
5049
_subscription = purchaseUpdated.listen((purchaseDetailsList) {
5150
_listenToPurchaseUpdated(purchaseDetailsList);
@@ -77,7 +76,7 @@ class _MyAppState extends State<_MyApp> {
7776
await _connection.queryProductDetails(_kProductIds.toSet());
7877
if (productDetailResponse.error != null) {
7978
setState(() {
80-
_queryProductError = productDetailResponse.error.message;
79+
_queryProductError = productDetailResponse.error!.message;
8180
_isAvailable = isAvailable;
8281
_products = productDetailResponse.productDetails;
8382
_purchases = [];
@@ -147,7 +146,7 @@ class _MyAppState extends State<_MyApp> {
147146
);
148147
} else {
149148
stack.add(Center(
150-
child: Text(_queryProductError),
149+
child: Text(_queryProductError!),
151150
));
152151
}
153152
if (_purchasePending) {
@@ -236,7 +235,7 @@ class _MyAppState extends State<_MyApp> {
236235
}));
237236
productList.addAll(_products.map(
238237
(ProductDetails productDetails) {
239-
PurchaseDetails previousPurchase = purchases[productDetails.id];
238+
PurchaseDetails? previousPurchase = purchases[productDetails.id];
240239
return ListTile(
241240
title: Text(
242241
productDetails.title,
@@ -329,7 +328,7 @@ class _MyAppState extends State<_MyApp> {
329328
void deliverProduct(PurchaseDetails purchaseDetails) async {
330329
// IMPORTANT!! Always verify a purchase purchase details before delivering the product.
331330
if (purchaseDetails.productID == _kConsumableId) {
332-
await ConsumableStore.save(purchaseDetails.purchaseID);
331+
await ConsumableStore.save(purchaseDetails.purchaseID!);
333332
List<String> consumables = await ConsumableStore.load();
334333
setState(() {
335334
_purchasePending = false;
@@ -365,7 +364,7 @@ class _MyAppState extends State<_MyApp> {
365364
showPendingUI();
366365
} else {
367366
if (purchaseDetails.status == PurchaseStatus.error) {
368-
handleError(purchaseDetails.error);
367+
handleError(purchaseDetails.error!);
369368
} else if (purchaseDetails.status == PurchaseStatus.purchased) {
370369
bool valid = await _verifyPurchase(purchaseDetails);
371370
if (valid) {

packages/in_app_purchase/example/pubspec.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: Flutter Team <[email protected]>
55
dependencies:
66
flutter:
77
sdk: flutter
8-
shared_preferences: ^0.5.2
8+
shared_preferences: ^2.0.0-nullsafety
99

1010
dev_dependencies:
1111
flutter_driver:
@@ -19,11 +19,11 @@ dev_dependencies:
1919
path: ../
2020
integration_test:
2121
path: ../../integration_test
22-
pedantic: ^1.8.0
22+
pedantic: ^1.10.0
2323

2424
flutter:
2525
uses-material-design: true
2626

2727
environment:
28-
sdk: ">=2.3.0 <3.0.0"
28+
sdk: ">=2.12.0 <3.0.0"
2929
flutter: ">=1.9.1+hotfix.2"

packages/in_app_purchase/ios/Classes/FIAPReceiptManager.m

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5-
//
6-
// FIAPReceiptManager.m
7-
// in_app_purchase
8-
//
9-
// Created by Chris Yang on 3/2/19.
10-
//
11-
125
#import "FIAPReceiptManager.h"
136
#import <Flutter/Flutter.h>
147

packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ - (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
290290
}];
291291
}
292292

293-
#pragma mark - delegatestransactionIdentifier:
293+
#pragma mark - delegates:
294294

295295
- (void)handleTransactionsUpdated:(NSArray<SKPaymentTransaction *> *)transactions {
296296
NSMutableArray *maps = [NSMutableArray new];

packages/in_app_purchase/lib/src/billing_client_wrappers/billing_client_wrapper.dart

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,6 @@ class BillingClient {
5353
bool _enablePendingPurchases = false;
5454

5555
/// Creates a billing client.
56-
///
57-
/// The `onPurchasesUpdated` parameter must not be null.
5856
BillingClient(PurchasesUpdatedListener onPurchasesUpdated) {
5957
channel.setMethodCallHandler(callHandler);
6058
_callbacks[kOnPurchasesUpdated] = [onPurchasesUpdated];
@@ -74,11 +72,9 @@ class BillingClient {
7472
/// [`BillingClient#isReady()`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#isReady())
7573
/// to get the ready status of the BillingClient instance.
7674
Future<bool> isReady() async {
77-
bool? ready = await channel.invokeMethod<bool>('BillingClient#isReady()');
78-
if (ready == null) {
79-
return false;
80-
}
81-
return ready;
75+
final bool? ready =
76+
await channel.invokeMethod<bool>('BillingClient#isReady()');
77+
return ready ?? false;
8278
}
8379

8480
/// Enable the [BillingClientWrapper] to handle pending purchases.
@@ -234,7 +230,6 @@ class BillingClient {
234230
/// Consuming can only be done on an item that's owned, and as a result of consumption, the user will no longer own it.
235231
/// Consumption is done asynchronously. The method returns a Future containing a [BillingResultWrapper].
236232
///
237-
/// The `purchaseToken` must not be null.
238233
/// The `developerPayload` is the developer data associated with the purchase to be consumed, it defaults to null.
239234
///
240235
/// This wraps [`BillingClient#consumeAsync(String, ConsumeResponseListener)`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#consumeAsync(java.lang.String,%20com.android.billingclient.api.ConsumeResponseListener))
@@ -266,7 +261,6 @@ class BillingClient {
266261
/// Please refer to [acknowledge](https://developer.android.com/google/play/billing/billing_library_overview#acknowledge) for more
267262
/// details.
268263
///
269-
/// The `purchaseToken` must not be null.
270264
/// The `developerPayload` is the developer data associated with the purchase to be consumed, it defaults to null.
271265
///
272266
/// This wraps [`BillingClient#acknowledgePurchase(String, AcknowledgePurchaseResponseListener)`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#acknowledgePurchase(com.android.billingclient.api.AcknowledgePurchaseParams,%20com.android.billingclient.api.AcknowledgePurchaseResponseListener))
@@ -292,7 +286,7 @@ class BillingClient {
292286
final PurchasesUpdatedListener listener =
293287
_callbacks[kOnPurchasesUpdated]!.first as PurchasesUpdatedListener;
294288
listener(PurchasesResultWrapper.fromJson(
295-
Map<String, dynamic>.from(call.arguments)));
289+
call.arguments.cast<String, dynamic>()));
296290
break;
297291
case _kOnBillingServiceDisconnected:
298292
final int handle = call.arguments['handle'];

packages/in_app_purchase/lib/src/billing_client_wrappers/purchase_wrapper.dart

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class PurchaseWrapper {
3535
required this.sku,
3636
required this.isAutoRenewing,
3737
required this.originalJson,
38-
required this.developerPayload,
38+
this.developerPayload,
3939
required this.isAcknowledged,
4040
required this.purchaseState});
4141

@@ -104,7 +104,9 @@ class PurchaseWrapper {
104104
///
105105
/// For [SkuType.subs] this means that the subscription is canceled when it is
106106
/// false.
107-
final bool? isAutoRenewing;
107+
///
108+
/// The value is `false` for [SkuType.inapp] products.
109+
final bool isAutoRenewing;
108110

109111
/// Details about this purchase, in JSON.
110112
///
@@ -116,8 +118,9 @@ class PurchaseWrapper {
116118
final String originalJson;
117119

118120
/// The payload specified by the developer when the purchase was acknowledged or consumed.
119-
@JsonKey(defaultValue: '')
120-
final String developerPayload;
121+
///
122+
/// The value is `null` if it wasn't specified when the purchase was acknowledged or consumed.
123+
final String? developerPayload;
121124

122125
/// Whether the purchase has been acknowledged.
123126
///
@@ -186,8 +189,9 @@ class PurchaseHistoryRecordWrapper {
186189
final String originalJson;
187190

188191
/// The payload specified by the developer when the purchase was acknowledged or consumed.
189-
@JsonKey(defaultValue: '')
190-
final String developerPayload;
192+
///
193+
/// If the value is `null` if it wasn't specified when the purchase was acknowledged or consumed.
194+
final String? developerPayload;
191195

192196
@override
193197
bool operator ==(Object other) {
@@ -248,7 +252,6 @@ class PurchasesResultWrapper {
248252
///
249253
/// This can represent either the status of the "query purchase history" half
250254
/// of the operation and the "user made purchases" transaction itself.
251-
@JsonKey(defaultValue: BillingResponse.error)
252255
final BillingResponse responseCode;
253256

254257
/// The list of successful purchases made in this transaction.

packages/in_app_purchase/lib/src/billing_client_wrappers/purchase_wrapper.g.dart

Lines changed: 9 additions & 66 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/in_app_purchase/lib/src/in_app_purchase/app_store_connection.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ class AppStoreConnection implements InAppPurchaseConnection {
6060
productIdentifier: purchaseParam.productDetails.id,
6161
quantity: 1,
6262
applicationUsername: purchaseParam.applicationUserName,
63-
simulatesAskToBuyInSandbox: purchaseParam.simulatesAskToBuyInSandbox,
63+
// ignore: deprecated_member_use_from_same_package
64+
simulatesAskToBuyInSandbox: purchaseParam.simulatesAskToBuyInSandbox ||
65+
purchaseParam.sandboxTesting,
6466
requestData: null));
6567
return true; // There's no error feedback from iOS here to return.
6668
}

packages/in_app_purchase/lib/src/in_app_purchase/purchase_details.dart

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,15 @@ class PurchaseParam {
107107

108108
/// @deprecated Use [simulatesAskToBuyInSandbox] instead.
109109
///
110-
/// This parameter has no effect and will be removed shortly.
110+
/// Only available on iOS, set it to `true` to produce an "ask to buy" flow for this payment in the sandbox.
111+
///
112+
/// See also [SKPaymentWrapper.simulatesAskToBuyInSandbox].
111113
@deprecated
112114
final bool sandboxTesting;
113115

114116
/// Only available on iOS, set it to `true` to produce an "ask to buy" flow for this payment in the sandbox.
117+
///
118+
/// See also [SKPaymentWrapper.simulatesAskToBuyInSandbox].
115119
final bool simulatesAskToBuyInSandbox;
116120
}
117121

@@ -142,7 +146,7 @@ class PurchaseDetails {
142146
///
143147
/// Milliseconds since epoch.
144148
///
145-
/// The value is `null` is [status] is not [PurchaseStatus.purchased].
149+
/// The value is `null` if [status] is not [PurchaseStatus.purchased].
146150
final String? transactionDate;
147151

148152
/// The status that this [PurchaseDetails] is currently on.

0 commit comments

Comments
 (0)