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

Commit e2828a4

Browse files
author
Chris Yang
committed
migrate example app
1 parent 2189695 commit e2828a4

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

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/lib/src/billing_client_wrappers/billing_client_wrapper.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ class BillingClient {
7272
/// [`BillingClient#isReady()`](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.html#isReady())
7373
/// to get the ready status of the BillingClient instance.
7474
Future<bool> isReady() async {
75-
final bool? ready = await channel.invokeMethod<bool>('BillingClient#isReady()');
75+
final bool? ready =
76+
await channel.invokeMethod<bool>('BillingClient#isReady()');
7677
return ready ?? false;
7778
}
7879

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ class AppStoreConnection implements InAppPurchaseConnection {
6161
quantity: 1,
6262
applicationUsername: purchaseParam.applicationUserName,
6363
// ignore: deprecated_member_use_from_same_package
64-
simulatesAskToBuyInSandbox: purchaseParam.simulatesAskToBuyInSandbox || purchaseParam.sandboxTesting,
64+
simulatesAskToBuyInSandbox: purchaseParam.simulatesAskToBuyInSandbox ||
65+
purchaseParam.sandboxTesting,
6566
requestData: null));
6667
return true; // There's no error feedback from iOS here to return.
6768
}

0 commit comments

Comments
 (0)