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

Commit 63b9fe8

Browse files
author
Chris Yang
committed
intial migrate
1 parent cb309bc commit 63b9fe8

38 files changed

+826
-656
lines changed

packages/in_app_purchase/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.4.0-nullsafety.0
2+
3+
* Migrate to nullsafety.
4+
* Deprecate `sandboxTesting`, introduce `simulatesAskToBuyInSandbox`.
5+
* **Breaking Change:**
6+
* Removed `callbackChannel` in `channels.dart`, see https://github.com/flutter/flutter/issues/69225.
7+
18
## 0.3.5+2
29

310
* Migrate deprecated references.

packages/in_app_purchase/build.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,3 @@ targets:
55
options:
66
any_map: true
77
create_to_json: true
8-
nullable: false

packages/in_app_purchase/example/lib/main.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
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
56
import 'dart:async';
67
import 'dart:io';
78
import 'package:flutter/material.dart';
@@ -254,8 +255,7 @@ class _MyAppState extends State<_MyApp> {
254255
onPressed: () {
255256
PurchaseParam purchaseParam = PurchaseParam(
256257
productDetails: productDetails,
257-
applicationUserName: null,
258-
sandboxTesting: true);
258+
applicationUserName: null);
259259
if (productDetails.id == _kConsumableId) {
260260
_connection.buyConsumable(
261261
purchaseParam: purchaseParam,

packages/in_app_purchase/example/pubspec.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ author: Flutter Team <[email protected]>
55
dependencies:
66
flutter:
77
sdk: flutter
8-
cupertino_icons: ^0.1.2
98
shared_preferences: ^0.5.2
109

1110
dev_dependencies:
12-
test: ^1.5.2
1311
flutter_driver:
1412
sdk: flutter
1513
in_app_purchase:

packages/in_app_purchase/integration_test/in_app_purchase_test.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
4+
// @dart = 2.10
45

56
import 'package:flutter_test/flutter_test.dart';
67
import 'package:in_app_purchase/in_app_purchase.dart';

packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar
7575
}];
7676
[_paymentQueueHandler startObservingPaymentQueue];
7777
_callbackChannel =
78-
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase_callback"
78+
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase"
7979
binaryMessenger:[registrar messenger]];
8080
return self;
8181
}
@@ -290,7 +290,7 @@ - (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
290290
}];
291291
}
292292

293-
#pragma mark - delegates
293+
#pragma mark - delegatestransactionIdentifier:
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: 36 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ class BillingClient {
5656
///
5757
/// The `onPurchasesUpdated` parameter must not be null.
5858
BillingClient(PurchasesUpdatedListener onPurchasesUpdated) {
59-
assert(onPurchasesUpdated != null);
6059
channel.setMethodCallHandler(callHandler);
6160
_callbacks[kOnPurchasesUpdated] = [onPurchasesUpdated];
6261
}
@@ -74,8 +73,13 @@ class BillingClient {
7473
/// Calls
7574
/// [`BillingClient#isReady()`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#isReady())
7675
/// to get the ready status of the BillingClient instance.
77-
Future<bool> isReady() async =>
78-
await channel.invokeMethod<bool>('BillingClient#isReady()');
76+
Future<bool> isReady() async {
77+
bool? ready = await channel.invokeMethod<bool>('BillingClient#isReady()');
78+
if (ready == null) {
79+
return false;
80+
}
81+
return ready;
82+
}
7983

8084
/// Enable the [BillingClientWrapper] to handle pending purchases.
8185
///
@@ -100,20 +104,20 @@ class BillingClient {
100104
/// This triggers the creation of a new `BillingClient` instance in Java if
101105
/// one doesn't already exist.
102106
Future<BillingResultWrapper> startConnection(
103-
{@required
104-
OnBillingServiceDisconnected onBillingServiceDisconnected}) async {
107+
{required OnBillingServiceDisconnected
108+
onBillingServiceDisconnected}) async {
105109
assert(_enablePendingPurchases,
106110
'enablePendingPurchases() must be called before calling startConnection');
107111
List<Function> disconnectCallbacks =
108112
_callbacks[_kOnBillingServiceDisconnected] ??= [];
109113
disconnectCallbacks.add(onBillingServiceDisconnected);
110-
return BillingResultWrapper.fromJson(await channel
114+
return BillingResultWrapper.fromJson((await channel
111115
.invokeMapMethod<String, dynamic>(
112116
"BillingClient#startConnection(BillingClientStateListener)",
113117
<String, dynamic>{
114118
'handle': disconnectCallbacks.length - 1,
115119
'enablePendingPurchases': _enablePendingPurchases
116-
}));
120+
}))!);
117121
}
118122

119123
/// Calls
@@ -137,15 +141,15 @@ class BillingClient {
137141
/// `SkuDetailsParams` as direct arguments instead of requiring it constructed
138142
/// and passed in as a class.
139143
Future<SkuDetailsResponseWrapper> querySkuDetails(
140-
{@required SkuType skuType, @required List<String> skusList}) async {
144+
{required SkuType skuType, required List<String> skusList}) async {
141145
final Map<String, dynamic> arguments = <String, dynamic>{
142146
'skuType': SkuTypeConverter().toJson(skuType),
143147
'skusList': skusList
144148
};
145-
return SkuDetailsResponseWrapper.fromJson(await channel.invokeMapMethod<
149+
return SkuDetailsResponseWrapper.fromJson((await channel.invokeMapMethod<
146150
String, dynamic>(
147151
'BillingClient#querySkuDetailsAsync(SkuDetailsParams, SkuDetailsResponseListener)',
148-
arguments));
152+
arguments))!);
149153
}
150154

151155
/// Attempt to launch the Play Billing Flow for a given [skuDetails].
@@ -172,16 +176,16 @@ class BillingClient {
172176
/// and [the given
173177
/// accountId](https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder.html#setAccountId(java.lang.String)).
174178
Future<BillingResultWrapper> launchBillingFlow(
175-
{@required String sku, String accountId}) async {
179+
{required String sku, String? accountId}) async {
176180
assert(sku != null);
177181
final Map<String, dynamic> arguments = <String, dynamic>{
178182
'sku': sku,
179183
'accountId': accountId,
180184
};
181185
return BillingResultWrapper.fromJson(
182-
await channel.invokeMapMethod<String, dynamic>(
186+
(await channel.invokeMapMethod<String, dynamic>(
183187
'BillingClient#launchBillingFlow(Activity, BillingFlowParams)',
184-
arguments));
188+
arguments))!);
185189
}
186190

187191
/// Fetches recent purchases for the given [SkuType].
@@ -197,10 +201,11 @@ class BillingClient {
197201
/// skutype)`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient#querypurchases).
198202
Future<PurchasesResultWrapper> queryPurchases(SkuType skuType) async {
199203
assert(skuType != null);
200-
return PurchasesResultWrapper.fromJson(await channel
204+
return PurchasesResultWrapper.fromJson((await channel
201205
.invokeMapMethod<String, dynamic>(
202-
'BillingClient#queryPurchases(String)',
203-
<String, dynamic>{'skuType': SkuTypeConverter().toJson(skuType)}));
206+
'BillingClient#queryPurchases(String)', <String, dynamic>{
207+
'skuType': SkuTypeConverter().toJson(skuType)
208+
}))!);
204209
}
205210

206211
/// Fetches purchase history for the given [SkuType].
@@ -218,10 +223,10 @@ class BillingClient {
218223
/// listener)`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient#querypurchasehistoryasync).
219224
Future<PurchasesHistoryResult> queryPurchaseHistory(SkuType skuType) async {
220225
assert(skuType != null);
221-
return PurchasesHistoryResult.fromJson(await channel.invokeMapMethod<String,
222-
dynamic>(
226+
return PurchasesHistoryResult.fromJson((await channel.invokeMapMethod<
227+
String, dynamic>(
223228
'BillingClient#queryPurchaseHistoryAsync(String, PurchaseHistoryResponseListener)',
224-
<String, dynamic>{'skuType': SkuTypeConverter().toJson(skuType)}));
229+
<String, dynamic>{'skuType': SkuTypeConverter().toJson(skuType)}))!);
225230
}
226231

227232
/// Consumes a given in-app product.
@@ -234,15 +239,15 @@ class BillingClient {
234239
///
235240
/// 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))
236241
Future<BillingResultWrapper> consumeAsync(String purchaseToken,
237-
{String developerPayload}) async {
242+
{String? developerPayload}) async {
238243
assert(purchaseToken != null);
239-
return BillingResultWrapper.fromJson(await channel
244+
return BillingResultWrapper.fromJson((await channel
240245
.invokeMapMethod<String, dynamic>(
241246
'BillingClient#consumeAsync(String, ConsumeResponseListener)',
242-
<String, String>{
247+
<String, dynamic>{
243248
'purchaseToken': purchaseToken,
244249
'developerPayload': developerPayload,
245-
}));
250+
}))!);
246251
}
247252

248253
/// Acknowledge an in-app purchase.
@@ -266,15 +271,15 @@ class BillingClient {
266271
///
267272
/// 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))
268273
Future<BillingResultWrapper> acknowledgePurchase(String purchaseToken,
269-
{String developerPayload}) async {
274+
{String? developerPayload}) async {
270275
assert(purchaseToken != null);
271-
return BillingResultWrapper.fromJson(await channel.invokeMapMethod<String,
276+
return BillingResultWrapper.fromJson((await channel.invokeMapMethod<String,
272277
dynamic>(
273278
'BillingClient#(AcknowledgePurchaseParams params, (AcknowledgePurchaseParams, AcknowledgePurchaseResponseListener)',
274-
<String, String>{
279+
<String, dynamic>{
275280
'purchaseToken': purchaseToken,
276281
'developerPayload': developerPayload,
277-
}));
282+
}))!);
278283
}
279284

280285
/// The method call handler for [channel].
@@ -283,15 +288,15 @@ class BillingClient {
283288
switch (call.method) {
284289
case kOnPurchasesUpdated:
285290
// The purchases updated listener is a singleton.
286-
assert(_callbacks[kOnPurchasesUpdated].length == 1);
291+
assert(_callbacks[kOnPurchasesUpdated]!.length == 1);
287292
final PurchasesUpdatedListener listener =
288-
_callbacks[kOnPurchasesUpdated].first;
293+
_callbacks[kOnPurchasesUpdated]!.first as PurchasesUpdatedListener;
289294
listener(PurchasesResultWrapper.fromJson(
290-
call.arguments.cast<String, dynamic>()));
295+
Map<String, dynamic>.from(call.arguments)));
291296
break;
292297
case _kOnBillingServiceDisconnected:
293298
final int handle = call.arguments['handle'];
294-
await _callbacks[_kOnBillingServiceDisconnected][handle]();
299+
await _callbacks[_kOnBillingServiceDisconnected]![handle]();
295300
break;
296301
}
297302
}

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

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,59 +12,74 @@ part 'enum_converters.g.dart';
1212
///
1313
/// Use these in `@JsonSerializable()` classes by annotating them with
1414
/// `@BillingResponseConverter()`.
15-
class BillingResponseConverter implements JsonConverter<BillingResponse, int> {
15+
class BillingResponseConverter implements JsonConverter<BillingResponse, int?> {
1616
/// Default const constructor.
1717
const BillingResponseConverter();
1818

1919
@override
20-
BillingResponse fromJson(int json) => _$enumDecode<BillingResponse>(
21-
_$BillingResponseEnumMap.cast<BillingResponse, dynamic>(), json);
20+
BillingResponse fromJson(int? json) {
21+
if (json == null) {
22+
return BillingResponse.error;
23+
}
24+
return _$enumDecode<BillingResponse, dynamic>(
25+
_$BillingResponseEnumMap.cast<BillingResponse, dynamic>(), json);
26+
}
2227

2328
@override
24-
int toJson(BillingResponse object) => _$BillingResponseEnumMap[object];
29+
int toJson(BillingResponse object) => _$BillingResponseEnumMap[object]!;
2530
}
2631

2732
/// Serializer for [SkuType].
2833
///
2934
/// Use these in `@JsonSerializable()` classes by annotating them with
3035
/// `@SkuTypeConverter()`.
31-
class SkuTypeConverter implements JsonConverter<SkuType, String> {
36+
class SkuTypeConverter implements JsonConverter<SkuType, String?> {
3237
/// Default const constructor.
3338
const SkuTypeConverter();
3439

3540
@override
36-
SkuType fromJson(String json) =>
37-
_$enumDecode<SkuType>(_$SkuTypeEnumMap.cast<SkuType, dynamic>(), json);
41+
SkuType fromJson(String? json) {
42+
if (json == null) {
43+
return SkuType.inapp;
44+
}
45+
return _$enumDecode<SkuType, dynamic>(
46+
_$SkuTypeEnumMap.cast<SkuType, dynamic>(), json);
47+
}
3848

3949
@override
40-
String toJson(SkuType object) => _$SkuTypeEnumMap[object];
50+
String toJson(SkuType object) => _$SkuTypeEnumMap[object]!;
4151
}
4252

4353
// Define a class so we generate serializer helper methods for the enums
4454
@JsonSerializable()
4555
class _SerializedEnums {
46-
BillingResponse response;
47-
SkuType type;
48-
PurchaseStateWrapper purchaseState;
56+
late BillingResponse response;
57+
late SkuType type;
58+
late PurchaseStateWrapper purchaseState;
4959
}
5060

5161
/// Serializer for [PurchaseStateWrapper].
5262
///
5363
/// Use these in `@JsonSerializable()` classes by annotating them with
5464
/// `@PurchaseStateConverter()`.
5565
class PurchaseStateConverter
56-
implements JsonConverter<PurchaseStateWrapper, int> {
66+
implements JsonConverter<PurchaseStateWrapper, int?> {
5767
/// Default const constructor.
5868
const PurchaseStateConverter();
5969

6070
@override
61-
PurchaseStateWrapper fromJson(int json) => _$enumDecode<PurchaseStateWrapper>(
62-
_$PurchaseStateWrapperEnumMap.cast<PurchaseStateWrapper, dynamic>(),
63-
json);
71+
PurchaseStateWrapper fromJson(int? json) {
72+
if (json == null) {
73+
return PurchaseStateWrapper.unspecified_state;
74+
}
75+
return _$enumDecode<PurchaseStateWrapper, dynamic>(
76+
_$PurchaseStateWrapperEnumMap.cast<PurchaseStateWrapper, dynamic>(),
77+
json);
78+
}
6479

6580
@override
6681
int toJson(PurchaseStateWrapper object) =>
67-
_$PurchaseStateWrapperEnumMap[object];
82+
_$PurchaseStateWrapperEnumMap[object]!;
6883

6984
/// Converts the purchase state stored in `object` to a [PurchaseStatus].
7085
///
@@ -78,7 +93,5 @@ class PurchaseStateConverter
7893
case PurchaseStateWrapper.unspecified_state:
7994
return PurchaseStatus.error;
8095
}
81-
82-
throw ArgumentError('$object isn\'t mapped to PurchaseStatus');
8396
}
8497
}

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

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

0 commit comments

Comments
 (0)