1// Copyright 2014 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// The widget in this file is an empty mock for non-web platforms. See
6// `_platform_selectable_region_context_menu_web.dart` for the web
7// implementation.
8
9import 'framework.dart';
10import 'selection_container.dart';
11
12/// Function signature for `ui_web.platformViewRegistry.registerViewFactory`.
13@visibleForTesting
14typedef RegisterViewFactory = void Function(String, Object Function(int viewId), {bool isVisible});
15
16/// A widget that provides native selection context menu for its child subtree.
17///
18/// This widget currently only supports Flutter web. Using this widget in non-web
19/// platforms will throw [UnimplementedError]s.
20///
21/// In web platform, this widget registers a singleton platform view, i.e. a
22/// HTML DOM element. The created platform view will be shared between all
23/// [PlatformSelectableRegionContextMenu]s.
24///
25/// Only one [SelectionContainerDelegate] can attach to the
26/// [PlatformSelectableRegionContextMenu] at a time. Use [attach] method to make
27/// a [SelectionContainerDelegate] to be the active client.
28class PlatformSelectableRegionContextMenu extends StatelessWidget {
29 /// Creates a [PlatformSelectableRegionContextMenu]
30 // ignore: prefer_const_constructors_in_immutables
31 PlatformSelectableRegionContextMenu({
32 // ignore: avoid_unused_constructor_parameters
33 required Widget child,
34 super.key,
35 });
36
37 /// Attaches the `client` to be able to open platform-appropriate context menus.
38 static void attach(SelectionContainerDelegate client) => throw UnimplementedError();
39
40 /// Detaches the `client` from the platform-appropriate selection context menus.
41 static void detach(SelectionContainerDelegate client) => throw UnimplementedError();
42
43 /// Override this to provide a custom implementation of `ui_web.platformViewRegistry.registerViewFactory`.
44 ///
45 /// This should only be used for testing.
46 @visibleForTesting
47 static RegisterViewFactory? debugOverrideRegisterViewFactory;
48
49 @override
50 Widget build(BuildContext context) => throw UnimplementedError();
51}
52