[web] ui.platformViewRegistry => ui_web.platformViewRegistry (#127493)
Now that `platformViewRegistry` is [exposed](https://github.com/flutter/engine/pull/41877) through `dart:ui_web`, we can do some cleanup here. Part of https://github.com/flutter/flutter/issues/126831
This commit is contained in:
@@ -3,11 +3,10 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:typed_data';
|
||||
import 'dart:ui';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'web/platform_views/web.dart';
|
||||
|
||||
class DrawPointsPage extends StatefulWidget {
|
||||
const DrawPointsPage({super.key});
|
||||
|
||||
|
||||
@@ -4,19 +4,16 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:html' as html;
|
||||
import 'dart:ui_web' as ui_web;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
// TODO(mdebbar): flutter/flutter#55000 Remove this conditional import once
|
||||
// web-only dart:ui_web APIs are exposed from a dedicated place.
|
||||
import 'platform_views/non_web.dart'
|
||||
if (dart.library.html) 'platform_views/web.dart';
|
||||
import 'recorder.dart';
|
||||
|
||||
const String benchmarkViewType = 'benchmark_element';
|
||||
|
||||
void _registerFactory() {
|
||||
platformViewRegistry.registerViewFactory(benchmarkViewType, (int viewId) {
|
||||
ui_web.platformViewRegistry.registerViewFactory(benchmarkViewType, (int viewId) {
|
||||
final html.Element htmlElement = html.DivElement();
|
||||
htmlElement.id = '${benchmarkViewType}_$viewId';
|
||||
htmlElement.innerText = 'Google';
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
// Copyright 2014 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: avoid_classes_with_only_static_members
|
||||
/// Shim for web_ui engine.PlatformViewRegistry
|
||||
/// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/ui.dart#L62
|
||||
// ignore: camel_case_types
|
||||
class platformViewRegistry {
|
||||
/// Shim for registerViewFactory
|
||||
/// https://github.com/flutter/engine/blob/master/lib/web_ui/lib/ui.dart#L72
|
||||
static void registerViewFactory(
|
||||
String viewTypeId, dynamic Function(int viewId) viewFactory,
|
||||
{bool isVisible = true}) {}
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
// Copyright 2014 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.
|
||||
|
||||
export 'dart:ui';
|
||||
@@ -3,8 +3,7 @@
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:html' as html;
|
||||
// platformViewRegistry is exposed in the web version
|
||||
import 'dart:ui' as ui show platformViewRegistry; // ignore: undefined_shown_name
|
||||
import 'dart:ui_web' as ui_web;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
@@ -37,8 +36,7 @@ void main() {
|
||||
int viewInstanceCount = 0;
|
||||
|
||||
platformViewsRegistry.getNextPlatformViewId();
|
||||
// ignore: undefined_prefixed_name, avoid_dynamic_calls
|
||||
ui.platformViewRegistry.registerViewFactory('MyView', (int viewId) {
|
||||
ui_web.platformViewRegistry.registerViewFactory('MyView', (int viewId) {
|
||||
viewInstanceCount += 1;
|
||||
return html.DivElement();
|
||||
});
|
||||
|
||||
@@ -9,6 +9,10 @@
|
||||
import 'framework.dart';
|
||||
import 'selection_container.dart';
|
||||
|
||||
/// Function signature for `ui_web.platformViewRegistry.registerViewFactory`.
|
||||
@visibleForTesting
|
||||
typedef RegisterViewFactory = void Function(String, Object Function(int viewId), {bool isVisible});
|
||||
|
||||
/// A widget that provides native selection context menu for its child subtree.
|
||||
///
|
||||
/// This widget currently only supports Flutter web. Using this widget in non-web
|
||||
@@ -36,6 +40,12 @@ class PlatformSelectableRegionContextMenu extends StatelessWidget {
|
||||
/// Detaches the `client` from the platform-appropriate selection context menus.
|
||||
static void detach(SelectionContainerDelegate client) => throw UnimplementedError();
|
||||
|
||||
/// Override this to provide a custom implementation of `ui_web.platformViewRegistry.registerViewFactory`.
|
||||
///
|
||||
/// This should only be used for testing.
|
||||
@visibleForTesting
|
||||
static RegisterViewFactory? debugOverrideRegisterViewFactory;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => throw UnimplementedError();
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
import 'dart:ui' as ui;
|
||||
import 'dart:ui_web' as ui_web;
|
||||
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
@@ -29,7 +29,7 @@ const int _kRightClickButton = 2;
|
||||
|
||||
typedef _WebSelectionCallBack = void Function(DomHTMLElement, DomMouseEvent);
|
||||
|
||||
/// Function signature for `ui.platformViewRegistry.registerViewFactory`.
|
||||
/// Function signature for `ui_web.platformViewRegistry.registerViewFactory`.
|
||||
@visibleForTesting
|
||||
typedef RegisterViewFactory = void Function(String, Object Function(int viewId), {bool isVisible});
|
||||
|
||||
@@ -67,10 +67,15 @@ class PlatformSelectableRegionContextMenu extends StatelessWidget {
|
||||
// Keeps track if this widget has already registered its view factories or not.
|
||||
static String? _registeredViewType;
|
||||
|
||||
/// See `_platform_selectable_region_context_menu_io.dart`.
|
||||
static RegisterViewFactory get _registerViewFactory =>
|
||||
debugOverrideRegisterViewFactory ?? ui_web.platformViewRegistry.registerViewFactory;
|
||||
|
||||
/// Override this to provide a custom implementation of [ui_web.platformViewRegistry.registerViewFactory].
|
||||
///
|
||||
/// This should only be used for testing.
|
||||
// See `_platform_selectable_region_context_menu_io.dart`.
|
||||
@visibleForTesting
|
||||
// ignore: undefined_prefixed_name, invalid_assignment, avoid_dynamic_calls
|
||||
static RegisterViewFactory registerViewFactory = ui.platformViewRegistry.registerViewFactory;
|
||||
static RegisterViewFactory? debugOverrideRegisterViewFactory;
|
||||
|
||||
// Registers the view factories for the interceptor widgets.
|
||||
static void _register() {
|
||||
@@ -100,7 +105,7 @@ class PlatformSelectableRegionContextMenu extends StatelessWidget {
|
||||
}
|
||||
|
||||
static String _registerWebSelectionCallback(_WebSelectionCallBack callback) {
|
||||
registerViewFactory(_viewType, (int viewId) {
|
||||
_registerViewFactory(_viewType, (int viewId) {
|
||||
final DomHTMLElement htmlElement = createDomHTMLDivElement();
|
||||
htmlElement
|
||||
..style.width = '100%'
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style license that can be
|
||||
// found in the LICENSE file.
|
||||
|
||||
// ignore_for_file: undefined_class, undefined_getter, undefined_setter
|
||||
|
||||
@TestOn('browser') // This file contains web-only library.
|
||||
library;
|
||||
|
||||
@@ -16,8 +14,7 @@ import 'package:flutter_test/flutter_test.dart';
|
||||
|
||||
void main() {
|
||||
html.Element? element;
|
||||
final RegisterViewFactory originalFactory = PlatformSelectableRegionContextMenu.registerViewFactory;
|
||||
PlatformSelectableRegionContextMenu.registerViewFactory = (String viewType, Object Function(int viewId) fn, {bool isVisible = true}) {
|
||||
PlatformSelectableRegionContextMenu.debugOverrideRegisterViewFactory = (String viewType, Object Function(int viewId) fn, {bool isVisible = true}) {
|
||||
element = fn(0) as html.Element;
|
||||
// The element needs to be attached to the document body to receive mouse
|
||||
// events.
|
||||
@@ -25,7 +22,7 @@ void main() {
|
||||
};
|
||||
// This force register the dom element.
|
||||
PlatformSelectableRegionContextMenu(child: const Placeholder());
|
||||
PlatformSelectableRegionContextMenu.registerViewFactory = originalFactory;
|
||||
PlatformSelectableRegionContextMenu.debugOverrideRegisterViewFactory = null;
|
||||
|
||||
test('DOM element is set up correctly', () async {
|
||||
expect(element, isNotNull);
|
||||
|
||||
Reference in New Issue
Block a user