|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
5 | | -// @dart = 2.10 |
6 | 5 | import 'dart:async'; |
7 | 6 | import 'dart:io'; |
8 | 7 | import 'package:flutter/material.dart'; |
@@ -33,19 +32,19 @@ class _MyApp extends StatefulWidget { |
33 | 32 |
|
34 | 33 | class _MyAppState extends State<_MyApp> { |
35 | 34 | final InAppPurchaseConnection _connection = InAppPurchaseConnection.instance; |
36 | | - StreamSubscription<List<PurchaseDetails>> _subscription; |
| 35 | + late StreamSubscription<List<PurchaseDetails>> _subscription; |
37 | 36 | List<String> _notFoundIds = []; |
38 | 37 | List<ProductDetails> _products = []; |
39 | 38 | List<PurchaseDetails> _purchases = []; |
40 | 39 | List<String> _consumables = []; |
41 | 40 | bool _isAvailable = false; |
42 | 41 | bool _purchasePending = false; |
43 | 42 | bool _loading = true; |
44 | | - String _queryProductError; |
| 43 | + String? _queryProductError; |
45 | 44 |
|
46 | 45 | @override |
47 | 46 | void initState() { |
48 | | - Stream purchaseUpdated = |
| 47 | + final Stream<List<PurchaseDetails>> purchaseUpdated = |
49 | 48 | InAppPurchaseConnection.instance.purchaseUpdatedStream; |
50 | 49 | _subscription = purchaseUpdated.listen((purchaseDetailsList) { |
51 | 50 | _listenToPurchaseUpdated(purchaseDetailsList); |
@@ -77,7 +76,7 @@ class _MyAppState extends State<_MyApp> { |
77 | 76 | await _connection.queryProductDetails(_kProductIds.toSet()); |
78 | 77 | if (productDetailResponse.error != null) { |
79 | 78 | setState(() { |
80 | | - _queryProductError = productDetailResponse.error.message; |
| 79 | + _queryProductError = productDetailResponse.error!.message; |
81 | 80 | _isAvailable = isAvailable; |
82 | 81 | _products = productDetailResponse.productDetails; |
83 | 82 | _purchases = []; |
@@ -147,7 +146,7 @@ class _MyAppState extends State<_MyApp> { |
147 | 146 | ); |
148 | 147 | } else { |
149 | 148 | stack.add(Center( |
150 | | - child: Text(_queryProductError), |
| 149 | + child: Text(_queryProductError!), |
151 | 150 | )); |
152 | 151 | } |
153 | 152 | if (_purchasePending) { |
@@ -236,7 +235,7 @@ class _MyAppState extends State<_MyApp> { |
236 | 235 | })); |
237 | 236 | productList.addAll(_products.map( |
238 | 237 | (ProductDetails productDetails) { |
239 | | - PurchaseDetails previousPurchase = purchases[productDetails.id]; |
| 238 | + PurchaseDetails? previousPurchase = purchases[productDetails.id]; |
240 | 239 | return ListTile( |
241 | 240 | title: Text( |
242 | 241 | productDetails.title, |
@@ -329,7 +328,7 @@ class _MyAppState extends State<_MyApp> { |
329 | 328 | void deliverProduct(PurchaseDetails purchaseDetails) async { |
330 | 329 | // IMPORTANT!! Always verify a purchase purchase details before delivering the product. |
331 | 330 | if (purchaseDetails.productID == _kConsumableId) { |
332 | | - await ConsumableStore.save(purchaseDetails.purchaseID); |
| 331 | + await ConsumableStore.save(purchaseDetails.purchaseID!); |
333 | 332 | List<String> consumables = await ConsumableStore.load(); |
334 | 333 | setState(() { |
335 | 334 | _purchasePending = false; |
@@ -365,7 +364,7 @@ class _MyAppState extends State<_MyApp> { |
365 | 364 | showPendingUI(); |
366 | 365 | } else { |
367 | 366 | if (purchaseDetails.status == PurchaseStatus.error) { |
368 | | - handleError(purchaseDetails.error); |
| 367 | + handleError(purchaseDetails.error!); |
369 | 368 | } else if (purchaseDetails.status == PurchaseStatus.purchased) { |
370 | 369 | bool valid = await _verifyPurchase(purchaseDetails); |
371 | 370 | if (valid) { |
|
0 commit comments