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

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Yang committed Feb 18, 2021
1 parent 63b9fe8 commit 612078d
Show file tree
Hide file tree
Showing 19 changed files with 211 additions and 186 deletions.
2 changes: 1 addition & 1 deletion packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 0.4.0-nullsafety.0
## 0.4.0

* Migrate to nullsafety.
* Deprecate `sandboxTesting`, introduce `simulatesAskToBuyInSandbox`.
Expand Down
17 changes: 8 additions & 9 deletions packages/in_app_purchase/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// @dart = 2.10
import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
Expand Down Expand Up @@ -33,19 +32,19 @@ class _MyApp extends StatefulWidget {

class _MyAppState extends State<_MyApp> {
final InAppPurchaseConnection _connection = InAppPurchaseConnection.instance;
StreamSubscription<List<PurchaseDetails>> _subscription;
late StreamSubscription<List<PurchaseDetails>> _subscription;
List<String> _notFoundIds = [];
List<ProductDetails> _products = [];
List<PurchaseDetails> _purchases = [];
List<String> _consumables = [];
bool _isAvailable = false;
bool _purchasePending = false;
bool _loading = true;
String _queryProductError;
String? _queryProductError;

@override
void initState() {
Stream purchaseUpdated =
final Stream<List<PurchaseDetails>> purchaseUpdated =
InAppPurchaseConnection.instance.purchaseUpdatedStream;
_subscription = purchaseUpdated.listen((purchaseDetailsList) {
_listenToPurchaseUpdated(purchaseDetailsList);
Expand Down Expand Up @@ -77,7 +76,7 @@ class _MyAppState extends State<_MyApp> {
await _connection.queryProductDetails(_kProductIds.toSet());
if (productDetailResponse.error != null) {
setState(() {
_queryProductError = productDetailResponse.error.message;
_queryProductError = productDetailResponse.error!.message;
_isAvailable = isAvailable;
_products = productDetailResponse.productDetails;
_purchases = [];
Expand Down Expand Up @@ -147,7 +146,7 @@ class _MyAppState extends State<_MyApp> {
);
} else {
stack.add(Center(
child: Text(_queryProductError),
child: Text(_queryProductError!),
));
}
if (_purchasePending) {
Expand Down Expand Up @@ -236,7 +235,7 @@ class _MyAppState extends State<_MyApp> {
}));
productList.addAll(_products.map(
(ProductDetails productDetails) {
PurchaseDetails previousPurchase = purchases[productDetails.id];
PurchaseDetails? previousPurchase = purchases[productDetails.id];
return ListTile(
title: Text(
productDetails.title,
Expand Down Expand Up @@ -329,7 +328,7 @@ class _MyAppState extends State<_MyApp> {
void deliverProduct(PurchaseDetails purchaseDetails) async {
// IMPORTANT!! Always verify a purchase purchase details before delivering the product.
if (purchaseDetails.productID == _kConsumableId) {
await ConsumableStore.save(purchaseDetails.purchaseID);
await ConsumableStore.save(purchaseDetails.purchaseID!);
List<String> consumables = await ConsumableStore.load();
setState(() {
_purchasePending = false;
Expand Down Expand Up @@ -365,7 +364,7 @@ class _MyAppState extends State<_MyApp> {
showPendingUI();
} else {
if (purchaseDetails.status == PurchaseStatus.error) {
handleError(purchaseDetails.error);
handleError(purchaseDetails.error!);
} else if (purchaseDetails.status == PurchaseStatus.purchased) {
bool valid = await _verifyPurchase(purchaseDetails);
if (valid) {
Expand Down
6 changes: 3 additions & 3 deletions packages/in_app_purchase/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ author: Flutter Team <[email protected]>
dependencies:
flutter:
sdk: flutter
shared_preferences: ^0.5.2
shared_preferences: ^2.0.0-nullsafety

dev_dependencies:
flutter_driver:
Expand All @@ -19,11 +19,11 @@ dev_dependencies:
path: ../
integration_test:
path: ../../integration_test
pedantic: ^1.8.0
pedantic: ^1.10.0

flutter:
uses-material-design: true

environment:
sdk: ">=2.3.0 <3.0.0"
sdk: ">=2.12.0 <3.0.0"
flutter: ">=1.9.1+hotfix.2"
7 changes: 0 additions & 7 deletions packages/in_app_purchase/ios/Classes/FIAPReceiptManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,6 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

//
// FIAPReceiptManager.m
// in_app_purchase
//
// Created by Chris Yang on 3/2/19.
//

#import "FIAPReceiptManager.h"
#import <Flutter/Flutter.h>

Expand Down
2 changes: 1 addition & 1 deletion packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ - (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
}];
}

#pragma mark - delegatestransactionIdentifier:
#pragma mark - delegates:

- (void)handleTransactionsUpdated:(NSArray<SKPaymentTransaction *> *)transactions {
NSMutableArray *maps = [NSMutableArray new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ class BillingClient {
bool _enablePendingPurchases = false;

/// Creates a billing client.
///
/// The `onPurchasesUpdated` parameter must not be null.
BillingClient(PurchasesUpdatedListener onPurchasesUpdated) {
channel.setMethodCallHandler(callHandler);
_callbacks[kOnPurchasesUpdated] = [onPurchasesUpdated];
Expand All @@ -74,11 +72,9 @@ class BillingClient {
/// [`BillingClient#isReady()`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#isReady())
/// to get the ready status of the BillingClient instance.
Future<bool> isReady() async {
bool? ready = await channel.invokeMethod<bool>('BillingClient#isReady()');
if (ready == null) {
return false;
}
return ready;
final bool? ready =
await channel.invokeMethod<bool>('BillingClient#isReady()');
return ready ?? false;
}

/// Enable the [BillingClientWrapper] to handle pending purchases.
Expand Down Expand Up @@ -234,7 +230,6 @@ class BillingClient {
/// Consuming can only be done on an item that's owned, and as a result of consumption, the user will no longer own it.
/// Consumption is done asynchronously. The method returns a Future containing a [BillingResultWrapper].
///
/// The `purchaseToken` must not be null.
/// The `developerPayload` is the developer data associated with the purchase to be consumed, it defaults to null.
///
/// 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))
Expand Down Expand Up @@ -266,7 +261,6 @@ class BillingClient {
/// Please refer to [acknowledge](https://developer.android.com/google/play/billing/billing_library_overview#acknowledge) for more
/// details.
///
/// The `purchaseToken` must not be null.
/// The `developerPayload` is the developer data associated with the purchase to be consumed, it defaults to null.
///
/// 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))
Expand All @@ -292,7 +286,7 @@ class BillingClient {
final PurchasesUpdatedListener listener =
_callbacks[kOnPurchasesUpdated]!.first as PurchasesUpdatedListener;
listener(PurchasesResultWrapper.fromJson(
Map<String, dynamic>.from(call.arguments)));
call.arguments.cast<String, dynamic>()));
break;
case _kOnBillingServiceDisconnected:
final int handle = call.arguments['handle'];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class PurchaseWrapper {
required this.sku,
required this.isAutoRenewing,
required this.originalJson,
required this.developerPayload,
this.developerPayload,
required this.isAcknowledged,
required this.purchaseState});

Expand Down Expand Up @@ -104,7 +104,9 @@ class PurchaseWrapper {
///
/// For [SkuType.subs] this means that the subscription is canceled when it is
/// false.
final bool? isAutoRenewing;
///
/// The value is `false` for [SkuType.inapp] products.
final bool isAutoRenewing;

/// Details about this purchase, in JSON.
///
Expand All @@ -116,8 +118,9 @@ class PurchaseWrapper {
final String originalJson;

/// The payload specified by the developer when the purchase was acknowledged or consumed.
@JsonKey(defaultValue: '')
final String developerPayload;
///
/// The value is `null` if it wasn't specified when the purchase was acknowledged or consumed.
final String? developerPayload;

/// Whether the purchase has been acknowledged.
///
Expand Down Expand Up @@ -186,8 +189,9 @@ class PurchaseHistoryRecordWrapper {
final String originalJson;

/// The payload specified by the developer when the purchase was acknowledged or consumed.
@JsonKey(defaultValue: '')
final String developerPayload;
///
/// If the value is `null` if it wasn't specified when the purchase was acknowledged or consumed.
final String? developerPayload;

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

/// The list of successful purchases made in this transaction.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class AppStoreConnection implements InAppPurchaseConnection {
productIdentifier: purchaseParam.productDetails.id,
quantity: 1,
applicationUsername: purchaseParam.applicationUserName,
simulatesAskToBuyInSandbox: purchaseParam.simulatesAskToBuyInSandbox,
// ignore: deprecated_member_use_from_same_package
simulatesAskToBuyInSandbox: purchaseParam.simulatesAskToBuyInSandbox ||
purchaseParam.sandboxTesting,
requestData: null));
return true; // There's no error feedback from iOS here to return.
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,15 @@ class PurchaseParam {

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

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

Expand Down Expand Up @@ -142,7 +146,7 @@ class PurchaseDetails {
///
/// Milliseconds since epoch.
///
/// The value is `null` is [status] is not [PurchaseStatus.purchased].
/// The value is `null` if [status] is not [PurchaseStatus.purchased].
final String? transactionDate;

/// The status that this [PurchaseDetails] is currently on.
Expand Down
Loading

0 comments on commit 612078d

Please sign in to comment.