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

Commit

Permalink
intial migrate
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Yang committed Feb 17, 2021
1 parent cb309bc commit 63b9fe8
Show file tree
Hide file tree
Showing 38 changed files with 826 additions and 656 deletions.
7 changes: 7 additions & 0 deletions packages/in_app_purchase/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
## 0.4.0-nullsafety.0

* Migrate to nullsafety.
* Deprecate `sandboxTesting`, introduce `simulatesAskToBuyInSandbox`.
* **Breaking Change:**
* Removed `callbackChannel` in `channels.dart`, see https://github.com/flutter/flutter/issues/69225.

## 0.3.5+2

* Migrate deprecated references.
Expand Down
1 change: 0 additions & 1 deletion packages/in_app_purchase/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,3 @@ targets:
options:
any_map: true
create_to_json: true
nullable: false
4 changes: 2 additions & 2 deletions packages/in_app_purchase/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// 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 @@ -254,8 +255,7 @@ class _MyAppState extends State<_MyApp> {
onPressed: () {
PurchaseParam purchaseParam = PurchaseParam(
productDetails: productDetails,
applicationUserName: null,
sandboxTesting: true);
applicationUserName: null);
if (productDetails.id == _kConsumableId) {
_connection.buyConsumable(
purchaseParam: purchaseParam,
Expand Down
2 changes: 0 additions & 2 deletions packages/in_app_purchase/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ author: Flutter Team <flutter-dev@googlegroups.com>
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
shared_preferences: ^0.5.2

dev_dependencies:
test: ^1.5.2
flutter_driver:
sdk: flutter
in_app_purchase:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright 2019, the Chromium project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart = 2.10

import 'package:flutter_test/flutter_test.dart';
import 'package:in_app_purchase/in_app_purchase.dart';
Expand Down
4 changes: 2 additions & 2 deletions packages/in_app_purchase/ios/Classes/InAppPurchasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ - (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar> *)registrar
}];
[_paymentQueueHandler startObservingPaymentQueue];
_callbackChannel =
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase_callback"
[FlutterMethodChannel methodChannelWithName:@"plugins.flutter.io/in_app_purchase"
binaryMessenger:[registrar messenger]];
return self;
}
Expand Down Expand Up @@ -290,7 +290,7 @@ - (void)refreshReceipt:(FlutterMethodCall *)call result:(FlutterResult)result {
}];
}

#pragma mark - delegates
#pragma mark - delegatestransactionIdentifier:

- (void)handleTransactionsUpdated:(NSArray<SKPaymentTransaction *> *)transactions {
NSMutableArray *maps = [NSMutableArray new];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ class BillingClient {
///
/// The `onPurchasesUpdated` parameter must not be null.
BillingClient(PurchasesUpdatedListener onPurchasesUpdated) {
assert(onPurchasesUpdated != null);
channel.setMethodCallHandler(callHandler);
_callbacks[kOnPurchasesUpdated] = [onPurchasesUpdated];
}
Expand All @@ -74,8 +73,13 @@ class BillingClient {
/// Calls
/// [`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 =>
await channel.invokeMethod<bool>('BillingClient#isReady()');
Future<bool> isReady() async {
bool? ready = await channel.invokeMethod<bool>('BillingClient#isReady()');
if (ready == null) {
return false;
}
return ready;
}

/// Enable the [BillingClientWrapper] to handle pending purchases.
///
Expand All @@ -100,20 +104,20 @@ class BillingClient {
/// This triggers the creation of a new `BillingClient` instance in Java if
/// one doesn't already exist.
Future<BillingResultWrapper> startConnection(
{@required
OnBillingServiceDisconnected onBillingServiceDisconnected}) async {
{required OnBillingServiceDisconnected
onBillingServiceDisconnected}) async {
assert(_enablePendingPurchases,
'enablePendingPurchases() must be called before calling startConnection');
List<Function> disconnectCallbacks =
_callbacks[_kOnBillingServiceDisconnected] ??= [];
disconnectCallbacks.add(onBillingServiceDisconnected);
return BillingResultWrapper.fromJson(await channel
return BillingResultWrapper.fromJson((await channel
.invokeMapMethod<String, dynamic>(
"BillingClient#startConnection(BillingClientStateListener)",
<String, dynamic>{
'handle': disconnectCallbacks.length - 1,
'enablePendingPurchases': _enablePendingPurchases
}));
}))!);
}

/// Calls
Expand All @@ -137,15 +141,15 @@ class BillingClient {
/// `SkuDetailsParams` as direct arguments instead of requiring it constructed
/// and passed in as a class.
Future<SkuDetailsResponseWrapper> querySkuDetails(
{@required SkuType skuType, @required List<String> skusList}) async {
{required SkuType skuType, required List<String> skusList}) async {
final Map<String, dynamic> arguments = <String, dynamic>{
'skuType': SkuTypeConverter().toJson(skuType),
'skusList': skusList
};
return SkuDetailsResponseWrapper.fromJson(await channel.invokeMapMethod<
return SkuDetailsResponseWrapper.fromJson((await channel.invokeMapMethod<
String, dynamic>(
'BillingClient#querySkuDetailsAsync(SkuDetailsParams, SkuDetailsResponseListener)',
arguments));
arguments))!);
}

/// Attempt to launch the Play Billing Flow for a given [skuDetails].
Expand All @@ -172,16 +176,16 @@ class BillingClient {
/// and [the given
/// accountId](https://developer.android.com/reference/com/android/billingclient/api/BillingFlowParams.Builder.html#setAccountId(java.lang.String)).
Future<BillingResultWrapper> launchBillingFlow(
{@required String sku, String accountId}) async {
{required String sku, String? accountId}) async {
assert(sku != null);
final Map<String, dynamic> arguments = <String, dynamic>{
'sku': sku,
'accountId': accountId,
};
return BillingResultWrapper.fromJson(
await channel.invokeMapMethod<String, dynamic>(
(await channel.invokeMapMethod<String, dynamic>(
'BillingClient#launchBillingFlow(Activity, BillingFlowParams)',
arguments));
arguments))!);
}

/// Fetches recent purchases for the given [SkuType].
Expand All @@ -197,10 +201,11 @@ class BillingClient {
/// skutype)`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient#querypurchases).
Future<PurchasesResultWrapper> queryPurchases(SkuType skuType) async {
assert(skuType != null);
return PurchasesResultWrapper.fromJson(await channel
return PurchasesResultWrapper.fromJson((await channel
.invokeMapMethod<String, dynamic>(
'BillingClient#queryPurchases(String)',
<String, dynamic>{'skuType': SkuTypeConverter().toJson(skuType)}));
'BillingClient#queryPurchases(String)', <String, dynamic>{
'skuType': SkuTypeConverter().toJson(skuType)
}))!);
}

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

/// Consumes a given in-app product.
Expand All @@ -234,15 +239,15 @@ class BillingClient {
///
/// 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))
Future<BillingResultWrapper> consumeAsync(String purchaseToken,
{String developerPayload}) async {
{String? developerPayload}) async {
assert(purchaseToken != null);
return BillingResultWrapper.fromJson(await channel
return BillingResultWrapper.fromJson((await channel
.invokeMapMethod<String, dynamic>(
'BillingClient#consumeAsync(String, ConsumeResponseListener)',
<String, String>{
<String, dynamic>{
'purchaseToken': purchaseToken,
'developerPayload': developerPayload,
}));
}))!);
}

/// Acknowledge an in-app purchase.
Expand All @@ -266,15 +271,15 @@ class BillingClient {
///
/// 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))
Future<BillingResultWrapper> acknowledgePurchase(String purchaseToken,
{String developerPayload}) async {
{String? developerPayload}) async {
assert(purchaseToken != null);
return BillingResultWrapper.fromJson(await channel.invokeMapMethod<String,
return BillingResultWrapper.fromJson((await channel.invokeMapMethod<String,
dynamic>(
'BillingClient#(AcknowledgePurchaseParams params, (AcknowledgePurchaseParams, AcknowledgePurchaseResponseListener)',
<String, String>{
<String, dynamic>{
'purchaseToken': purchaseToken,
'developerPayload': developerPayload,
}));
}))!);
}

/// The method call handler for [channel].
Expand All @@ -283,15 +288,15 @@ class BillingClient {
switch (call.method) {
case kOnPurchasesUpdated:
// The purchases updated listener is a singleton.
assert(_callbacks[kOnPurchasesUpdated].length == 1);
assert(_callbacks[kOnPurchasesUpdated]!.length == 1);
final PurchasesUpdatedListener listener =
_callbacks[kOnPurchasesUpdated].first;
_callbacks[kOnPurchasesUpdated]!.first as PurchasesUpdatedListener;
listener(PurchasesResultWrapper.fromJson(
call.arguments.cast<String, dynamic>()));
Map<String, dynamic>.from(call.arguments)));
break;
case _kOnBillingServiceDisconnected:
final int handle = call.arguments['handle'];
await _callbacks[_kOnBillingServiceDisconnected][handle]();
await _callbacks[_kOnBillingServiceDisconnected]![handle]();
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,59 +12,74 @@ part 'enum_converters.g.dart';
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@BillingResponseConverter()`.
class BillingResponseConverter implements JsonConverter<BillingResponse, int> {
class BillingResponseConverter implements JsonConverter<BillingResponse, int?> {
/// Default const constructor.
const BillingResponseConverter();

@override
BillingResponse fromJson(int json) => _$enumDecode<BillingResponse>(
_$BillingResponseEnumMap.cast<BillingResponse, dynamic>(), json);
BillingResponse fromJson(int? json) {
if (json == null) {
return BillingResponse.error;
}
return _$enumDecode<BillingResponse, dynamic>(
_$BillingResponseEnumMap.cast<BillingResponse, dynamic>(), json);
}

@override
int toJson(BillingResponse object) => _$BillingResponseEnumMap[object];
int toJson(BillingResponse object) => _$BillingResponseEnumMap[object]!;
}

/// Serializer for [SkuType].
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@SkuTypeConverter()`.
class SkuTypeConverter implements JsonConverter<SkuType, String> {
class SkuTypeConverter implements JsonConverter<SkuType, String?> {
/// Default const constructor.
const SkuTypeConverter();

@override
SkuType fromJson(String json) =>
_$enumDecode<SkuType>(_$SkuTypeEnumMap.cast<SkuType, dynamic>(), json);
SkuType fromJson(String? json) {
if (json == null) {
return SkuType.inapp;
}
return _$enumDecode<SkuType, dynamic>(
_$SkuTypeEnumMap.cast<SkuType, dynamic>(), json);
}

@override
String toJson(SkuType object) => _$SkuTypeEnumMap[object];
String toJson(SkuType object) => _$SkuTypeEnumMap[object]!;
}

// Define a class so we generate serializer helper methods for the enums
@JsonSerializable()
class _SerializedEnums {
BillingResponse response;
SkuType type;
PurchaseStateWrapper purchaseState;
late BillingResponse response;
late SkuType type;
late PurchaseStateWrapper purchaseState;
}

/// Serializer for [PurchaseStateWrapper].
///
/// Use these in `@JsonSerializable()` classes by annotating them with
/// `@PurchaseStateConverter()`.
class PurchaseStateConverter
implements JsonConverter<PurchaseStateWrapper, int> {
implements JsonConverter<PurchaseStateWrapper, int?> {
/// Default const constructor.
const PurchaseStateConverter();

@override
PurchaseStateWrapper fromJson(int json) => _$enumDecode<PurchaseStateWrapper>(
_$PurchaseStateWrapperEnumMap.cast<PurchaseStateWrapper, dynamic>(),
json);
PurchaseStateWrapper fromJson(int? json) {
if (json == null) {
return PurchaseStateWrapper.unspecified_state;
}
return _$enumDecode<PurchaseStateWrapper, dynamic>(
_$PurchaseStateWrapperEnumMap.cast<PurchaseStateWrapper, dynamic>(),
json);
}

@override
int toJson(PurchaseStateWrapper object) =>
_$PurchaseStateWrapperEnumMap[object];
_$PurchaseStateWrapperEnumMap[object]!;

/// Converts the purchase state stored in `object` to a [PurchaseStatus].
///
Expand All @@ -78,7 +93,5 @@ class PurchaseStateConverter
case PurchaseStateWrapper.unspecified_state:
return PurchaseStatus.error;
}

throw ArgumentError('$object isn\'t mapped to PurchaseStatus');
}
}

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

Loading

0 comments on commit 63b9fe8

Please sign in to comment.