From 9bf96ec416e154ee15ef5188da38d701f2d518d4 Mon Sep 17 00:00:00 2001 From: Maurits van Beusekom Date: Wed, 7 Apr 2021 15:13:01 +0200 Subject: [PATCH] Remove NoopInAppPurchase implementation --- .../lib/src/in_app_purchase_platform.dart | 13 ++++++++++--- .../lib/src/noop_in_app_purchase.dart | 10 ---------- .../test/in_app_purchase_platform_test.dart | 5 ++--- 3 files changed, 12 insertions(+), 16 deletions(-) delete mode 100644 packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/noop_in_app_purchase.dart diff --git a/packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/in_app_purchase_platform.dart b/packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/in_app_purchase_platform.dart index dd314b2951b5..dee78ee0f816 100644 --- a/packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/in_app_purchase_platform.dart +++ b/packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/in_app_purchase_platform.dart @@ -6,7 +6,6 @@ import 'dart:async'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; -import 'noop_in_app_purchase.dart'; import 'types/types.dart'; /// The interface that implementations of in_app_purchase must implement. @@ -22,10 +21,18 @@ abstract class InAppPurchasePlatform extends PlatformInterface { static final Object _token = Object(); - static InAppPurchasePlatform _instance = NoopInAppPurchase(); + static InAppPurchasePlatform? _instance; /// The default instance of [InAppPurchasePlatform] to use. - static InAppPurchasePlatform get instance => _instance; + static InAppPurchasePlatform get instance { + final InAppPurchasePlatform? platform = _instance; + if (platform == null) { + throw UnimplementedError( + 'No platform specific implementation set. Please make sure you set the `instance` with a valid platform specific implementation of the `InAppPurchasePlatform` class.'); + } + + return platform; + } /// Platform-specific plugins should set this with their own platform-specific /// class that extends [InAppPurchasePlatform] when they register themselves. diff --git a/packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/noop_in_app_purchase.dart b/packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/noop_in_app_purchase.dart deleted file mode 100644 index 6808c07dae60..000000000000 --- a/packages/in_app_purchase/in_app_purchase_platform_interface/lib/src/noop_in_app_purchase.dart +++ /dev/null @@ -1,10 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -import 'in_app_purchase_platform.dart'; - -/// Temporary no-operation implementation of the [InAppPurchasePlatform] which -/// was added to return as default implementation for the [InAppPurchasePlatform.instance] -/// property. -class NoopInAppPurchase extends InAppPurchasePlatform {} diff --git a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart index 69b6484b7298..9001a0612c46 100644 --- a/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart +++ b/packages/in_app_purchase/in_app_purchase_platform_interface/test/in_app_purchase_platform_test.dart @@ -4,7 +4,6 @@ import 'package:flutter_test/flutter_test.dart'; import 'package:in_app_purchase_platform_interface/in_app_purchase_platform_interface.dart'; -import 'package:in_app_purchase_platform_interface/src/noop_in_app_purchase.dart'; import 'package:mockito/mockito.dart'; import 'package:plugin_platform_interface/plugin_platform_interface.dart'; @@ -12,8 +11,8 @@ void main() { TestWidgetsFlutterBinding.ensureInitialized(); group('$InAppPurchasePlatform', () { - test('$NoopInAppPurchase is the default instance', () { - expect(InAppPurchasePlatform.instance, isA()); + test('default instance is null and throws unimplemented exception', () { + expect(() => InAppPurchasePlatform.instance, throwsUnimplementedError); }); test('Cannot be implemented with `implements`', () {