From f267ed35ca53bc33caae7f652e193e0d7f11807d Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 28 Nov 2023 00:09:56 -0800 Subject: [PATCH 1/9] platform interface --- .../CHANGELOG.md | 3 ++ .../LICENSE | 25 +++++++++++ .../README.md | 26 +++++++++++ ...ointer_interceptor_platform_interface.dart | 7 +++ .../lib/src/default_pointer_interceptor.dart | 21 +++++++++ .../lib/src/pointer_interceptor_platform.dart | 45 +++++++++++++++++++ .../pubspec.yaml | 18 ++++++++ 7 files changed, 145 insertions(+) create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/CHANGELOG.md create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/LICENSE create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/pointer_interceptor_platform.dart create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/CHANGELOG.md b/packages/pointer_interceptor/pointer_interceptor_platform_interface/CHANGELOG.md new file mode 100644 index 000000000000..f4c3d3e1bc4e --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.10.0 + +* Initial release from migration to federated architecture. diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/LICENSE b/packages/pointer_interceptor/pointer_interceptor_platform_interface/LICENSE new file mode 100644 index 000000000000..c6823b81eb84 --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/LICENSE @@ -0,0 +1,25 @@ +Copyright 2013 The Flutter Authors. All rights reserved. + +Redistribution and use in source and binary forms, with or without modification, +are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. + * Redistributions in binary form must reproduce the above + copyright notice, this list of conditions and the following + disclaimer in the documentation and/or other materials provided + with the distribution. + * Neither the name of Google Inc. nor the names of its + contributors may be used to endorse or promote products derived + from this software without specific prior written permission. + +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND +ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; +LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON +ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS +SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md b/packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md new file mode 100644 index 000000000000..6d9558441396 --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md @@ -0,0 +1,26 @@ +# pointer_interceptor_platform_interface + +A common platform interface for the [`pointer_interceptor`][1] plugin. + +This interface allows platform-specific implementations of the `pointer_interceptor` +plugin, as well as the plugin itself, to ensure they are supporting the +same interface. + +# Usage + +To implement a new platform-specific implementation of `pointer_interceptor`, extend +[`PointerInterceptorPlatform`][2] with an implementation that performs the +platform-specific behavior, and when you register your plugin, set the default +`PointerInterceptorPlatform` by calling +`PointerInterceptorPlatform.instance = MyPointerInterceptorPlatform()`. + +# Note on breaking changes + +Strongly prefer non-breaking changes (such as adding a method to the interface) +over breaking changes for this package. + +See https://flutter.dev/go/platform-interface-breaking-changes for a discussion +on why a less-clean interface is preferable to a breaking change. + +[1]: ../pointer_interceptor +[2]: lib/pointer_interceptor_platform_interface.dart \ No newline at end of file diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart new file mode 100644 index 000000000000..dfdace230f1e --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart @@ -0,0 +1,7 @@ +// 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. + +library pointer_interceptor; + +export 'src/pointer_interceptor_platform.dart'; diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart new file mode 100644 index 000000000000..0c935e6ab1f8 --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart @@ -0,0 +1,21 @@ +// 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. + +// ignore_for_file: avoid_print + +import 'package:flutter/widgets.dart'; + +import 'pointer_interceptor_platform.dart'; + +/// A default implementation of [PointerInterceptorPlatform]. +class DefaultPointerInterceptor extends PointerInterceptorPlatform { + @override + Widget buildWidget({ + required Widget child, + bool debug = false, + Key? key, + }) { + return child; + } +} diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/pointer_interceptor_platform.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/pointer_interceptor_platform.dart new file mode 100644 index 000000000000..59b558a7b1f3 --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/pointer_interceptor_platform.dart @@ -0,0 +1,45 @@ +// 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 'package:flutter/widgets.dart'; +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; + +import 'default_pointer_interceptor.dart'; + +/// Platform-specific implementations should set this with their own +/// platform-specific class that extends [PointerInterceptorPlatform] when +/// they register themselves. +abstract class PointerInterceptorPlatform extends PlatformInterface { + /// Constructs a PointerInterceptorPlatform. + PointerInterceptorPlatform() : super(token: _token); + + static final Object _token = Object(); + + static PointerInterceptorPlatform _instance = DefaultPointerInterceptor(); + + static set instance(PointerInterceptorPlatform? instance) { + if (instance == null) { + throw AssertionError( + 'Platform interfaces can only be set to a non-null instance'); + } + + PlatformInterface.verify(instance, _token); + _instance = instance; + } + + /// The default instance of [PointerInterceptorPlatform] to use. + /// + /// Defaults to [DefaultPointerInterceptor], which does not do anything + static PointerInterceptorPlatform get instance => _instance; + + /// Platform-specific implementations should override this function their own + /// implementation of a pointer interceptor widget. + Widget buildWidget({ + required Widget child, + bool debug = false, + Key? key, + }) { + throw UnimplementedError('buildWidget() has not been implemented.'); + } +} diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml new file mode 100644 index 000000000000..5a20f7ecdaae --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml @@ -0,0 +1,18 @@ +name: pointer_interceptor_platform_interface +description: "A common platform interface for the pointer_interceptor plugin." +version: 1.0.0 +publish_to: none + +environment: + sdk: '>=3.1.0' + flutter: '>=3.13.0' + +dependencies: + flutter: + sdk: flutter + plugin_platform_interface: ^2.1.0 + +dev_dependencies: + flutter_test: + sdk: flutter + From 206058a5dd2f2c5af5b80a1c8bd72b374b6c1ed1 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 28 Nov 2023 11:37:41 -0800 Subject: [PATCH 2/9] pr comments --- ...ointer_interceptor_platform_interface.dart | 2 -- .../lib/src/default_pointer_interceptor.dart | 4 +--- .../pubspec.yaml | 6 ++++-- .../pointer_interceptor_platform_test.dart | 19 +++++++++++++++++++ 4 files changed, 24 insertions(+), 7 deletions(-) create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart index dfdace230f1e..284f6225ea9d 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/pointer_interceptor_platform_interface.dart @@ -2,6 +2,4 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -library pointer_interceptor; - export 'src/pointer_interceptor_platform.dart'; diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart index 0c935e6ab1f8..e3a591120d5e 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/lib/src/default_pointer_interceptor.dart @@ -2,13 +2,11 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// ignore_for_file: avoid_print - import 'package:flutter/widgets.dart'; import 'pointer_interceptor_platform.dart'; -/// A default implementation of [PointerInterceptorPlatform]. +/// A default no-op implementation of [PointerInterceptorPlatform]. class DefaultPointerInterceptor extends PointerInterceptorPlatform { @override Widget buildWidget({ diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml index 5a20f7ecdaae..6e201c5338b4 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml @@ -1,7 +1,9 @@ name: pointer_interceptor_platform_interface description: "A common platform interface for the pointer_interceptor plugin." -version: 1.0.0 -publish_to: none +repository: https://github.com/flutter/packages/tree/main/packages/pointer_interceptor/pointer_interceptor_platform_interface +issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+label%3A%22p%3A+pointer_interceptor%22 + +version: 0.10.0 environment: sdk: '>=3.1.0' diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart new file mode 100644 index 000000000000..70d2c1ba7cb9 --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart @@ -0,0 +1,19 @@ +// 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 'package:flutter/cupertino.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test('Default implementation of PointerInterceptor should return child', () { + final PointerInterceptorPlatform pointerInterceptorPlatform = + PointerInterceptorPlatform.instance; + + final Container testChild = Container(); + expect(pointerInterceptorPlatform.buildWidget(child: testChild), testChild); + }); +} From 0fbd9679abf872d4388157b1355622beb7989e09 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 28 Nov 2023 11:45:01 -0800 Subject: [PATCH 3/9] update read me links --- .../pointer_interceptor_platform_interface/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md b/packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md index 6d9558441396..a2030bfb6321 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/README.md @@ -22,5 +22,5 @@ over breaking changes for this package. See https://flutter.dev/go/platform-interface-breaking-changes for a discussion on why a less-clean interface is preferable to a breaking change. -[1]: ../pointer_interceptor -[2]: lib/pointer_interceptor_platform_interface.dart \ No newline at end of file +[1]: https://pub.dev/packages/pointer_interceptor +[2]: lib/src/pointer_interceptor_platform.dart \ No newline at end of file From 29dd58918ced8bba74ee0f9850f1abbbb7fca8d7 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 28 Nov 2023 12:03:41 -0800 Subject: [PATCH 4/9] pubspec + authors file --- .../pointer_interceptor_platform_interface/AUTHORS | 6 ++++++ .../pointer_interceptor_platform_interface/pubspec.yaml | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/AUTHORS diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/AUTHORS b/packages/pointer_interceptor/pointer_interceptor_platform_interface/AUTHORS new file mode 100644 index 000000000000..e8063a8cd6e5 --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/AUTHORS @@ -0,0 +1,6 @@ +# Below is a list of people and organizations that have contributed +# to the project. Names should be added to the list like so: +# +# Name/Organization + +Google Inc. diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml index 6e201c5338b4..dc6d5dfad7e0 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml @@ -6,7 +6,7 @@ issue_tracker: https://github.com/flutter/flutter/issues?q=is%3Aissue+is%3Aopen+ version: 0.10.0 environment: - sdk: '>=3.1.0' + sdk: '>=3.1.0 <4.0.0' flutter: '>=3.13.0' dependencies: From 38c41e292439772eaadfa9d9e80a5884adfba82c Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 28 Nov 2023 12:13:20 -0800 Subject: [PATCH 5/9] fix unimplemented test --- .../test/pointer_interceptor_platform_test.dart | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart index 70d2c1ba7cb9..bf3291deea49 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/pointer_interceptor_platform_test.dart @@ -9,11 +9,19 @@ import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platf void main() { TestWidgetsFlutterBinding.ensureInitialized(); - test('Default implementation of PointerInterceptor should return child', () { - final PointerInterceptorPlatform pointerInterceptorPlatform = - PointerInterceptorPlatform.instance; + test( + 'Default implementation of PointerInterceptorPlatform should throw unimplemented error', + () { + final PointerInterceptorPlatform unimplementedPointerInterceptorPlatform = + UnimplementedPointerInterceptorPlatform(); final Container testChild = Container(); - expect(pointerInterceptorPlatform.buildWidget(child: testChild), testChild); + expect( + () => unimplementedPointerInterceptorPlatform.buildWidget( + child: testChild), + throwsUnimplementedError); }); } + +class UnimplementedPointerInterceptorPlatform + extends PointerInterceptorPlatform {} From c8c90514e24571332eccd6bc82aca830b2e96669 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Tue, 28 Nov 2023 12:24:24 -0800 Subject: [PATCH 6/9] add topics --- .../pointer_interceptor_platform_interface/pubspec.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml index dc6d5dfad7e0..9fc0e25f3e57 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml @@ -18,3 +18,6 @@ dev_dependencies: flutter_test: sdk: flutter +topics: + - widgets + - platform views \ No newline at end of file From 4f8025e10c573b4ea851421e3f140ca242b3e00e Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 29 Nov 2023 10:28:01 -0800 Subject: [PATCH 7/9] add test for default behaviour --- .../default_pointer_interceptor_test.dart | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart new file mode 100644 index 000000000000..5ace98f33ed4 --- /dev/null +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart @@ -0,0 +1,21 @@ +// 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 'package:flutter/cupertino.dart'; +import 'package:flutter_test/flutter_test.dart'; +import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart'; + +void main() { + TestWidgetsFlutterBinding.ensureInitialized(); + + test( + 'Default implementation of PointerInterceptor does not do anything', + () { + final PointerInterceptorPlatform defaultPointerInterceptor = + PointerInterceptorPlatform.instance; + + final Container testChild = Container(); + expect(defaultPointerInterceptor.buildWidget(child: testChild), testChild); + }); +} From 98aad1bcd36689913fd1db573b8f27df142d5df2 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 29 Nov 2023 10:34:41 -0800 Subject: [PATCH 8/9] format --- .../test/default_pointer_interceptor_test.dart | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart index 5ace98f33ed4..1489cd90dc1b 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/test/default_pointer_interceptor_test.dart @@ -9,9 +9,7 @@ import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platf void main() { TestWidgetsFlutterBinding.ensureInitialized(); - test( - 'Default implementation of PointerInterceptor does not do anything', - () { + test('Default implementation of PointerInterceptor does not do anything', () { final PointerInterceptorPlatform defaultPointerInterceptor = PointerInterceptorPlatform.instance; From 3054075d1f621f4d0001f5765de4e347d3259a38 Mon Sep 17 00:00:00 2001 From: Louise Hsu Date: Wed, 29 Nov 2023 11:28:49 -0800 Subject: [PATCH 9/9] add topic --- .../pointer_interceptor_platform_interface/pubspec.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml index 9fc0e25f3e57..7586e47863d3 100644 --- a/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml +++ b/packages/pointer_interceptor/pointer_interceptor_platform_interface/pubspec.yaml @@ -20,4 +20,5 @@ dev_dependencies: topics: - widgets - - platform views \ No newline at end of file + - platform views + - pointer-interceptor \ No newline at end of file