From 9ab2360786062bdf7744d4131557ee0b4f005e53 Mon Sep 17 00:00:00 2001 From: David Iglesias Teixeira Date: Wed, 3 Jan 2024 11:05:54 -0800 Subject: [PATCH] Clean imports, make onElementCreated a tear-off --- .../example/integration_test/widget_test.dart | 2 -- .../pointer_interceptor_web/example/lib/main.dart | 1 - .../lib/pointer_interceptor_web.dart | 14 ++++++-------- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/packages/pointer_interceptor/pointer_interceptor_web/example/integration_test/widget_test.dart b/packages/pointer_interceptor/pointer_interceptor_web/example/integration_test/widget_test.dart index 09948fdf2e8a..d712f6fbfa00 100644 --- a/packages/pointer_interceptor/pointer_interceptor_web/example/integration_test/widget_test.dart +++ b/packages/pointer_interceptor/pointer_interceptor_web/example/integration_test/widget_test.dart @@ -8,9 +8,7 @@ import 'package:flutter/src/widgets/framework.dart'; import 'package:flutter_test/flutter_test.dart'; import 'package:integration_test/integration_test.dart'; - import 'package:pointer_interceptor_web_example/main.dart' as app; - import 'package:web/web.dart' as web; final Finder nonClickableButtonFinder = diff --git a/packages/pointer_interceptor/pointer_interceptor_web/example/lib/main.dart b/packages/pointer_interceptor/pointer_interceptor_web/example/lib/main.dart index 96cdb726c1a0..d25e8913f419 100644 --- a/packages/pointer_interceptor/pointer_interceptor_web/example/lib/main.dart +++ b/packages/pointer_interceptor/pointer_interceptor_web/example/lib/main.dart @@ -8,7 +8,6 @@ import 'dart:ui_web' as ui_web; import 'package:flutter/material.dart'; import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart'; import 'package:pointer_interceptor_web/pointer_interceptor_web.dart'; - import 'package:web/web.dart' as web; const String _htmlElementViewType = '_htmlElementViewType'; diff --git a/packages/pointer_interceptor/pointer_interceptor_web/lib/pointer_interceptor_web.dart b/packages/pointer_interceptor/pointer_interceptor_web/lib/pointer_interceptor_web.dart index d82cdb91e42a..2ae4bf5f505b 100644 --- a/packages/pointer_interceptor/pointer_interceptor_web/lib/pointer_interceptor_web.dart +++ b/packages/pointer_interceptor/pointer_interceptor_web/lib/pointer_interceptor_web.dart @@ -4,9 +4,7 @@ import 'package:flutter/widgets.dart'; import 'package:flutter_web_plugins/flutter_web_plugins.dart'; - import 'package:pointer_interceptor_platform_interface/pointer_interceptor_platform_interface.dart'; - import 'package:web/web.dart' as web; /// The web implementation of the `PointerInterceptor` widget. @@ -18,6 +16,11 @@ class PointerInterceptorWeb extends PointerInterceptorPlatform { PointerInterceptorPlatform.instance = PointerInterceptorWeb(); } + // Slightly modify the created `element` (for `debug` mode). + void _onElementCreated(Object element) { + (element as web.HTMLElement).style.backgroundColor = 'rgba(255, 0, 0, .5)'; + } + @override Widget buildWidget({ required Widget child, @@ -35,12 +38,7 @@ class PointerInterceptorWeb extends PointerInterceptorPlatform { child: HtmlElementView.fromTagName( tagName: 'div', isVisible: false, - onElementCreated: debug - ? (Object element) { - element as web.HTMLElement; - element.style.backgroundColor = 'rgba(255, 0, 0, .5)'; - } - : null, + onElementCreated: debug ? _onElementCreated : null, ), ), child,