Skip to content

Commit d3bbef8

Browse files
authored
[in_app_purchase] Remove the custom analysis options, fix failing lints. (flutter#3220)
The custom analysis_options was excluding the lint for documenting all public methods. So this PR mostly adds Dartdocs, however there are a few non Dartdoc changes: * example/lib/main.dart: make MyApp and kAutoConsume private. * lib/src/in_app_purchase/app_store_connection.dart: adds a @VisibleForTesting AppStoreConnection constructor. * lib/src/in_app_purchase/app_store_connection.dart: adds a @VisibleForTesting AppStoreConnection.observer getter.
1 parent edfaa43 commit d3bbef8

18 files changed

+119
-20
lines changed

packages/in_app_purchase/analysis_options.yaml

-10
This file was deleted.

packages/in_app_purchase/example/lib/consumable_store.dart

+11-2
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,31 @@
55
import 'dart:async';
66
import 'package:shared_preferences/shared_preferences.dart';
77

8-
// This is just a development prototype for locally storing consumables. Do not
9-
// use this.
8+
/// A store of consumable items.
9+
///
10+
/// This is a development prototype tha stores consumables in the shared
11+
/// preferences. Do not use this in real world apps.
1012
class ConsumableStore {
1113
static const String _kPrefKey = 'consumables';
1214
static Future<void> _writes = Future.value();
1315

16+
/// Adds a consumable with ID `id` to the store.
17+
///
18+
/// The consumable is only added after the returned Future is complete.
1419
static Future<void> save(String id) {
1520
_writes = _writes.then((void _) => _doSave(id));
1621
return _writes;
1722
}
1823

24+
/// Consumes a consumable with ID `id` from the store.
25+
///
26+
/// The consumable was only consumed after the returned Future is complete.
1927
static Future<void> consume(String id) {
2028
_writes = _writes.then((void _) => _doConsume(id));
2129
return _writes;
2230
}
2331

32+
/// Returns the list of consumables from the store.
2433
static Future<List<String>> load() async {
2534
return (await SharedPreferences.getInstance()).getStringList(_kPrefKey) ??
2635
[];

packages/in_app_purchase/example/lib/main.dart

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ void main() {
1313
// [enablePendingPurchases](https://developer.android.com/reference/com/android/billingclient/api/BillingClient.Builder.html#enablependingpurchases)
1414
// as part of initializing the app.
1515
InAppPurchaseConnection.enablePendingPurchases();
16-
runApp(MyApp());
16+
runApp(_MyApp());
1717
}
1818

19-
const bool kAutoConsume = true;
19+
const bool _kAutoConsume = true;
2020

2121
const String _kConsumableId = 'consumable';
2222
const List<String> _kProductIds = <String>[
@@ -25,12 +25,12 @@ const List<String> _kProductIds = <String>[
2525
'subscription'
2626
];
2727

28-
class MyApp extends StatefulWidget {
28+
class _MyApp extends StatefulWidget {
2929
@override
3030
_MyAppState createState() => _MyAppState();
3131
}
3232

33-
class _MyAppState extends State<MyApp> {
33+
class _MyAppState extends State<_MyApp> {
3434
final InAppPurchaseConnection _connection = InAppPurchaseConnection.instance;
3535
StreamSubscription<List<PurchaseDetails>> _subscription;
3636
List<String> _notFoundIds = [];
@@ -257,7 +257,7 @@ class _MyAppState extends State<MyApp> {
257257
if (productDetails.id == _kConsumableId) {
258258
_connection.buyConsumable(
259259
purchaseParam: purchaseParam,
260-
autoConsume: kAutoConsume || Platform.isIOS);
260+
autoConsume: _kAutoConsume || Platform.isIOS);
261261
} else {
262262
_connection.buyNonConsumable(
263263
purchaseParam: purchaseParam);
@@ -374,7 +374,7 @@ class _MyAppState extends State<MyApp> {
374374
}
375375
}
376376
if (Platform.isAndroid) {
377-
if (!kAutoConsume && purchaseDetails.productID == _kConsumableId) {
377+
if (!_kAutoConsume && purchaseDetails.productID == _kConsumableId) {
378378
await InAppPurchaseConnection.instance
379379
.consumePurchase(purchaseDetails);
380380
}

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

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'purchase_wrapper.dart';
1212
import 'sku_details_wrapper.dart';
1313
import 'enum_converters.dart';
1414

15+
/// Method identifier for the OnPurchaseUpdated method channel method.
1516
@visibleForTesting
1617
const String kOnPurchasesUpdated =
1718
'PurchasesUpdatedListener#onPurchasesUpdated(int, List<Purchase>)';
@@ -51,6 +52,9 @@ typedef void PurchasesUpdatedListener(PurchasesResultWrapper purchasesResult);
5152
class BillingClient {
5253
bool _enablePendingPurchases = false;
5354

55+
/// Creates a billing client.
56+
///
57+
/// The `onPurchasesUpdated` parameter must not be null.
5458
BillingClient(PurchasesUpdatedListener onPurchasesUpdated) {
5559
assert(onPurchasesUpdated != null);
5660
channel.setMethodCallHandler(callHandler);
@@ -273,6 +277,7 @@ class BillingClient {
273277
}));
274278
}
275279

280+
/// The method call handler for [channel].
276281
@visibleForTesting
277282
Future<void> callHandler(MethodCall call) async {
278283
switch (call.method) {
@@ -309,36 +314,47 @@ enum BillingResponse {
309314
// WARNING: Changes to this class need to be reflected in our generated code.
310315
// Run `flutter packages pub run build_runner watch` to rebuild and watch for
311316
// further changes.
317+
/// The requested feature is not supported by Play Store on the current device.
312318
@JsonValue(-2)
313319
featureNotSupported,
314320

321+
/// The play Store service is not connected now - potentially transient state.
315322
@JsonValue(-1)
316323
serviceDisconnected,
317324

325+
/// Success.
318326
@JsonValue(0)
319327
ok,
320328

329+
/// The user pressed back or canceled a dialog.
321330
@JsonValue(1)
322331
userCanceled,
323332

333+
/// The network connection is down.
324334
@JsonValue(2)
325335
serviceUnavailable,
326336

337+
/// The billing API version is not supported for the type requested.
327338
@JsonValue(3)
328339
billingUnavailable,
329340

341+
/// The requested product is not available for purchase.
330342
@JsonValue(4)
331343
itemUnavailable,
332344

345+
/// Invalid arguments provided to the API.
333346
@JsonValue(5)
334347
developerError,
335348

349+
/// Fatal error during the API action.
336350
@JsonValue(6)
337351
error,
338352

353+
/// Failure to purchase since item is already owned.
339354
@JsonValue(7)
340355
itemAlreadyOwned,
341356

357+
/// Failure to consume since item is not owned.
342358
@JsonValue(8)
343359
itemNotOwned,
344360
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ part 'enum_converters.g.dart';
1313
/// Use these in `@JsonSerializable()` classes by annotating them with
1414
/// `@BillingResponseConverter()`.
1515
class BillingResponseConverter implements JsonConverter<BillingResponse, int> {
16+
/// Default const constructor.
1617
const BillingResponseConverter();
1718

1819
@override
@@ -28,6 +29,7 @@ class BillingResponseConverter implements JsonConverter<BillingResponse, int> {
2829
/// Use these in `@JsonSerializable()` classes by annotating them with
2930
/// `@SkuTypeConverter()`.
3031
class SkuTypeConverter implements JsonConverter<SkuType, String> {
32+
/// Default const constructor.
3133
const SkuTypeConverter();
3234

3335
@override
@@ -52,6 +54,7 @@ class _SerializedEnums {
5254
/// `@PurchaseStateConverter()`.
5355
class PurchaseStateConverter
5456
implements JsonConverter<PurchaseStateWrapper, int> {
57+
/// Default const constructor.
5558
const PurchaseStateConverter();
5659

5760
@override
@@ -63,6 +66,9 @@ class PurchaseStateConverter
6366
int toJson(PurchaseStateWrapper object) =>
6467
_$PurchaseStateWrapperEnumMap[object];
6568

69+
/// Converts the purchase state stored in `object` to a [PurchaseStatus].
70+
///
71+
/// [PurchaseStateWrapper.unspecified_state] is mapped to [PurchaseStatus.error].
6672
PurchaseStatus toPurchaseStatus(PurchaseStateWrapper object) {
6773
switch (object) {
6874
case PurchaseStateWrapper.pending:

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

+8
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ part 'purchase_wrapper.g.dart';
2424
@JsonSerializable()
2525
@PurchaseStateConverter()
2626
class PurchaseWrapper {
27+
/// Creates a purchase wrapper with the given purchase details.
2728
@visibleForTesting
2829
PurchaseWrapper(
2930
{@required this.orderId,
@@ -38,6 +39,7 @@ class PurchaseWrapper {
3839
@required this.isAcknowledged,
3940
@required this.purchaseState});
4041

42+
/// Factory for creating a [PurchaseWrapper] from a [Map] with the purchase details.
4143
factory PurchaseWrapper.fromJson(Map map) => _$PurchaseWrapperFromJson(map);
4244

4345
@override
@@ -132,6 +134,7 @@ class PurchaseWrapper {
132134
// For now, we keep them separated classes to be consistent with Android's BillingClient implementation.
133135
@JsonSerializable()
134136
class PurchaseHistoryRecordWrapper {
137+
/// Creates a [PurchaseHistoryRecordWrapper] with the given record details.
135138
@visibleForTesting
136139
PurchaseHistoryRecordWrapper({
137140
@required this.purchaseTime,
@@ -142,6 +145,7 @@ class PurchaseHistoryRecordWrapper {
142145
@required this.developerPayload,
143146
});
144147

148+
/// Factory for creating a [PurchaseHistoryRecordWrapper] from a [Map] with the record details.
145149
factory PurchaseHistoryRecordWrapper.fromJson(Map map) =>
146150
_$PurchaseHistoryRecordWrapperFromJson(map);
147151

@@ -197,11 +201,13 @@ class PurchaseHistoryRecordWrapper {
197201
@JsonSerializable()
198202
@BillingResponseConverter()
199203
class PurchasesResultWrapper {
204+
/// Creates a [PurchasesResultWrapper] with the given purchase result details.
200205
PurchasesResultWrapper(
201206
{@required this.responseCode,
202207
@required this.billingResult,
203208
@required this.purchasesList});
204209

210+
/// Factory for creating a [PurchaseResultWrapper] from a [Map] with the result details.
205211
factory PurchasesResultWrapper.fromJson(Map<String, dynamic> map) =>
206212
_$PurchasesResultWrapperFromJson(map);
207213

@@ -240,9 +246,11 @@ class PurchasesResultWrapper {
240246
@JsonSerializable()
241247
@BillingResponseConverter()
242248
class PurchasesHistoryResult {
249+
/// Creates a [PurchasesHistoryResult] with the provided history.
243250
PurchasesHistoryResult(
244251
{@required this.billingResult, @required this.purchaseHistoryRecordList});
245252

253+
/// Factory for creating a [PurchasesHistoryResult] from a [Map] with the history result details.
246254
factory PurchasesHistoryResult.fromJson(Map<String, dynamic> map) =>
247255
_$PurchasesHistoryResultFromJson(map);
248256

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

+5
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ part 'sku_details_wrapper.g.dart';
1919
@JsonSerializable()
2020
@SkuTypeConverter()
2121
class SkuDetailsWrapper {
22+
/// Creates a [SkuDetailsWrapper] with the given purchase details.
2223
@visibleForTesting
2324
SkuDetailsWrapper({
2425
@required this.description,
@@ -47,6 +48,7 @@ class SkuDetailsWrapper {
4748
factory SkuDetailsWrapper.fromJson(Map map) =>
4849
_$SkuDetailsWrapperFromJson(map);
4950

51+
/// Textual description of the product.
5052
final String description;
5153

5254
/// Trial period in ISO 8601 format.
@@ -78,6 +80,8 @@ class SkuDetailsWrapper {
7880

7981
/// Applies to [SkuType.subs], formatted in ISO 8601.
8082
final String subscriptionPeriod;
83+
84+
/// The product's title.
8185
final String title;
8286

8387
/// The [SkuType] of the product.
@@ -143,6 +147,7 @@ class SkuDetailsWrapper {
143147
/// Returned by [BillingClient.querySkuDetails].
144148
@JsonSerializable()
145149
class SkuDetailsResponseWrapper {
150+
/// Creates a [SkuDetailsResponseWrapper] with the given purchase details.
146151
@visibleForTesting
147152
SkuDetailsResponseWrapper(
148153
{@required this.billingResult, this.skuDetailsList});

packages/in_app_purchase/lib/src/channel.dart

+5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@
44

55
import 'package:flutter/services.dart';
66

7+
/// Method channel for the plugin's platform<-->Dart calls (all but the
8+
/// ios->Dart calls which are carried over the [callbackChannel]).
79
const MethodChannel channel =
810
MethodChannel('plugins.flutter.io/in_app_purchase');
911

12+
/// Method channel for the plugin's ios->Dart calls.
13+
// This is in a separate channel due to historic reasons only.
14+
// TODO(cyanglaz): Remove this. https://github.com/flutter/flutter/issues/69225
1015
const MethodChannel callbackChannel =
1116
MethodChannel('plugins.flutter.io/in_app_purchase_callback');

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

+11
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,25 @@ import '../../billing_client_wrappers.dart';
1818
/// This translates various `StoreKit` calls and responses into the
1919
/// generic plugin API.
2020
class AppStoreConnection implements InAppPurchaseConnection {
21+
/// Returns the singleton instance of the [AppStoreConnection] that should be
22+
/// used across the app.
2123
static AppStoreConnection get instance => _getOrCreateInstance();
2224
static AppStoreConnection _instance;
2325
static SKPaymentQueueWrapper _skPaymentQueueWrapper;
2426
static _TransactionObserver _observer;
2527

28+
/// Creates an [AppStoreConnection] object.
29+
///
30+
/// This constructor should only be used for testing, for any other purpose
31+
/// get the connection from the [instance] getter.
32+
@visibleForTesting
33+
AppStoreConnection();
34+
2635
Stream<List<PurchaseDetails>> get purchaseUpdatedStream =>
2736
_observer.purchaseUpdatedController.stream;
2837

38+
/// Callback handler for transaction status changes.
39+
@visibleForTesting
2940
static SKTransactionObserverWrapper get observer => _observer;
3041

3142
static AppStoreConnection _getOrCreateInstance() {

packages/in_app_purchase/lib/src/in_app_purchase/google_play_connection.dart

+9
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,18 @@ class GooglePlayConnection
3232
_purchaseUpdatedController = StreamController.broadcast();
3333
;
3434
}
35+
36+
/// Returns the singleton instance of the [GooglePlayConnection].
3537
static GooglePlayConnection get instance => _getOrCreateInstance();
3638
static GooglePlayConnection _instance;
3739

3840
Stream<List<PurchaseDetails>> get purchaseUpdatedStream =>
3941
_purchaseUpdatedController.stream;
4042
static StreamController<List<PurchaseDetails>> _purchaseUpdatedController;
4143

44+
/// The [BillingClient] that's abstracted by [GooglePlayConnection].
45+
///
46+
/// This field should not be used out of test code.
4247
@visibleForTesting
4348
final BillingClient billingClient;
4449

@@ -161,6 +166,10 @@ class GooglePlayConnection
161166
'The method <refreshPurchaseVerificationData> only works on iOS.');
162167
}
163168

169+
/// Resets the connection instance.
170+
///
171+
/// The next call to [instance] will create a new instance. Should only be
172+
/// used in tests.
164173
@visibleForTesting
165174
static void reset() => _instance = null;
166175

packages/in_app_purchase/lib/src/in_app_purchase/in_app_purchase_connection.dart

+8-1
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,13 @@ abstract class InAppPurchaseConnection {
269269
}
270270

271271
/// Which platform the request is on.
272-
enum IAPSource { GooglePlay, AppStore }
272+
enum IAPSource {
273+
/// Google's Play Store.
274+
GooglePlay,
275+
276+
/// Apple's App Store.
277+
AppStore
278+
}
273279

274280
/// Captures an error from the underlying purchase platform.
275281
///
@@ -279,6 +285,7 @@ enum IAPSource { GooglePlay, AppStore }
279285
/// * [ProductDetailsResponse] for error when querying product details.
280286
/// * [PurchaseDetails] for error happened in purchase.
281287
class IAPError {
288+
/// Creates a new IAP error object with the given error details.
282289
IAPError(
283290
{@required this.source,
284291
@required this.code,

packages/in_app_purchase/lib/src/in_app_purchase/product_details.dart

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'in_app_purchase_connection.dart';
1212
/// This class unifies the BillingClient's [SkuDetailsWrapper] and StoreKit's [SKProductWrapper]. You can use the common attributes in
1313
/// This class for simple operations. If you would like to see the detailed representation of the product, instead, use [skuDetails] on Android and [skProduct] on iOS.
1414
class ProductDetails {
15+
/// Creates a new product details object with the provided details.
1516
ProductDetails(
1617
{@required this.id,
1718
@required this.title,
@@ -66,6 +67,7 @@ class ProductDetails {
6667
///
6768
/// A list of [ProductDetails] can be obtained from the this response.
6869
class ProductDetailsResponse {
70+
/// Creates a new [ProductDetailsResponse] with the provided response details.
6971
ProductDetailsResponse(
7072
{@required this.productDetails, @required this.notFoundIDs, this.error});
7173

0 commit comments

Comments
 (0)