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

Commit 208b93d

Browse files
committed
Apply feedback from PR
1 parent 139289c commit 208b93d

9 files changed

+18
-49
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
## 1.0.0
22

3-
- Initial open-source release.
3+
* Initial open-source release.

packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/in_app_purchase_platform.dart

+6-19
Original file line numberDiff line numberDiff line change
@@ -21,26 +21,13 @@ abstract class InAppPurchasePlatform extends PlatformInterface {
2121

2222
static final Object _token = Object();
2323

24-
static InAppPurchasePlatform? _instance;
25-
26-
/// The default instance of [InAppPurchasePlatform] to use.
27-
static InAppPurchasePlatform get instance {
28-
final InAppPurchasePlatform? platform = _instance;
29-
if (platform == null) {
30-
throw UnimplementedError(
31-
'No platform specific implementation set. Please make sure you set the `instance` with a valid platform specific implementation of the `InAppPurchasePlatform` class.');
32-
}
33-
34-
return platform;
35-
}
36-
37-
/// Platform-specific plugins should set this with their own platform-specific
38-
/// class that extends [InAppPurchasePlatform] when they register themselves.
39-
// TODO(amirh): Extract common platform interface logic.
40-
// https://github.com/flutter/flutter/issues/43368
41-
static set instance(InAppPurchasePlatform instance) {
24+
//// Ensures that implementers are using `extends` rather than
25+
/// `implements` and throws [AssertionError] if not.
26+
///
27+
/// This is implemented as a static method so that it cannot be overridden
28+
/// with `noSuchMethod`.
29+
static void verifyToken(InAppPurchasePlatform instance) {
4230
PlatformInterface.verifyToken(instance, _token);
43-
_instance = instance;
4431
}
4532

4633
/// Listen to this broadcast stream to get real time update for purchases.

packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/types/in_app_purchase_error.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +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-
import 'in_app_purchase_source.dart';
6-
75
/// Captures an error from the underlying purchase platform.
86
///
97
/// The error can happen during the purchase, restoring a purchase, or querying product.
@@ -20,7 +18,7 @@ class IAPError {
2018
this.details});
2119

2220
/// Which source is the error on.
23-
final IAPSource source;
21+
final String source;
2422

2523
/// The error code.
2624
final String code;

packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/types/in_app_purchase_source.dart

-12
This file was deleted.

packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/types/purchase_status.dart

+3-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ enum PurchaseStatus {
2323

2424
/// The purchase has been restored to the device.
2525
///
26-
/// You should validate the receipt and if valid deliver the content. Once the
26+
/// You should validate the purchase and if valid deliver the content. Once the
2727
/// content has been delivered or if the receipt is invalid you should finish
28-
/// the purchase by calling the `finishPurchase` method.
28+
/// the purchase by calling the `finishPurchase` method. More information on
29+
/// verifying purchases can be found [here](https://pub.dev/packages/in_app_purchase#loading-previous-purchases).
2930
restored,
3031
}

packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/types/purchase_verification_data.dart

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +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-
import 'in_app_purchase_source.dart';
6-
75
/// Represents the data that is used to verify purchases.
86
///
97
/// The property [source] helps you to determine the method to verify purchases.
@@ -44,5 +42,5 @@ class PurchaseVerificationData {
4442
final String serverVerificationData;
4543

4644
/// Indicates the source of the purchase.
47-
final IAPSource source;
45+
final String source;
4846
}

packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/types/types.dart

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
// found in the LICENSE file.
44

55
export 'in_app_purchase_error.dart';
6-
export 'in_app_purchase_source.dart';
76
export 'product_details.dart';
87
export 'product_details_response.dart';
98
export 'purchase_details.dart';

packages/in_app_purchase/in_app_purchase_platform_interface/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ dev_dependencies:
1818

1919
environment:
2020
sdk: ">=2.12.0 <3.0.0"
21-
flutter: ">=1.22.0"
21+
flutter: ">=1.22.0"

packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart

+5-7
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,21 @@ void main() {
1111
TestWidgetsFlutterBinding.ensureInitialized();
1212

1313
group('$InAppPurchasePlatform', () {
14-
test('default instance is null and throws unimplemented exception', () {
15-
expect(() => InAppPurchasePlatform.instance, throwsUnimplementedError);
16-
});
17-
1814
test('Cannot be implemented with `implements`', () {
15+
final InAppPurchasePlatform instance = ImplementsInAppPurchasePlatform();
1916
expect(() {
20-
InAppPurchasePlatform.instance = ImplementsInAppPurchasePlatform();
17+
InAppPurchasePlatform.verifyToken(instance);
2118
}, throwsNoSuchMethodError);
2219
});
2320

2421
test('Can be extended', () {
25-
InAppPurchasePlatform.instance = ExtendsInAppPurchasePlatform();
22+
final InAppPurchasePlatform instance = ExtendsInAppPurchasePlatform();
23+
InAppPurchasePlatform.verifyToken(instance);
2624
});
2725

2826
test('Can be mocked with `implements`', () {
2927
final MockInAppPurchasePlatform mock = MockInAppPurchasePlatform();
30-
InAppPurchasePlatform.instance = mock;
28+
InAppPurchasePlatform.verifyToken(mock);
3129
});
3230

3331
test(

0 commit comments

Comments
 (0)