mirror of
https://github.com/bggRGjQaUbCoE/PiliPlus.git
synced 2026-07-24 04:20:12 +08:00
fix RichTextField desktop menu
Signed-off-by: dom <githubaccount56556@proton.me>
This commit is contained in:
@@ -1,354 +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_for_file: prefer_initializing_formals, uri_does_not_exist_in_doc_import
|
||||
|
||||
/// @docImport 'selectable_text.dart';
|
||||
/// @docImport 'selection_area.dart';
|
||||
/// @docImport 'text_field.dart';
|
||||
library;
|
||||
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/editable_text.dart';
|
||||
import 'package:flutter/cupertino.dart' hide EditableText, EditableTextState;
|
||||
import 'package:flutter/material.dart'
|
||||
hide EditableText, EditableTextState, AdaptiveTextSelectionToolbar;
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
/// The default context menu for text selection for the current platform.
|
||||
///
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.contextMenuBuilders}
|
||||
/// Typically, this widget would be passed to `contextMenuBuilder` in a
|
||||
/// supported parent widget, such as:
|
||||
///
|
||||
/// * [EditableText.contextMenuBuilder]
|
||||
/// * [TextField.contextMenuBuilder]
|
||||
/// * [CupertinoTextField.contextMenuBuilder]
|
||||
/// * [SelectionArea.contextMenuBuilder]
|
||||
/// * [SelectableText.contextMenuBuilder]
|
||||
/// {@endtemplate}
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [EditableText.getEditableButtonItems], which returns the default
|
||||
/// [ContextMenuButtonItem]s for [EditableText] on the platform.
|
||||
/// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds the button
|
||||
/// Widgets for the current platform given [ContextMenuButtonItem]s.
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar], which does the same thing as this
|
||||
/// widget but only for Cupertino context menus.
|
||||
/// * [TextSelectionToolbar], the default toolbar for Android.
|
||||
/// * [DesktopTextSelectionToolbar], the default toolbar for desktop platforms
|
||||
/// other than MacOS.
|
||||
/// * [CupertinoTextSelectionToolbar], the default toolbar for iOS.
|
||||
/// * [CupertinoDesktopTextSelectionToolbar], the default toolbar for MacOS.
|
||||
class AdaptiveTextSelectionToolbar extends StatelessWidget {
|
||||
/// Create an instance of [AdaptiveTextSelectionToolbar] with the
|
||||
/// given [children].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// * [AdaptiveTextSelectionToolbar.buttonItems], which takes a list of
|
||||
/// [ContextMenuButtonItem]s instead of [children] widgets.
|
||||
/// {@endtemplate}
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.editable}
|
||||
/// * [AdaptiveTextSelectionToolbar.editable], which builds the default
|
||||
/// children for an editable field.
|
||||
/// {@endtemplate}
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.editableText}
|
||||
/// * [AdaptiveTextSelectionToolbar.editableText], which builds the default
|
||||
/// children for an [EditableText].
|
||||
/// {@endtemplate}
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.selectable}
|
||||
/// * [AdaptiveTextSelectionToolbar.selectable], which builds the default
|
||||
/// children for content that is selectable but not editable.
|
||||
/// {@endtemplate}
|
||||
const AdaptiveTextSelectionToolbar({
|
||||
super.key,
|
||||
required this.children,
|
||||
required this.anchors,
|
||||
}) : buttonItems = null;
|
||||
|
||||
/// Create an instance of [AdaptiveTextSelectionToolbar] whose children will
|
||||
/// be built from the given [buttonItems].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.new}
|
||||
/// * [AdaptiveTextSelectionToolbar.new], which takes the children directly as
|
||||
/// a list of widgets.
|
||||
/// {@endtemplate}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable}
|
||||
const AdaptiveTextSelectionToolbar.buttonItems({
|
||||
super.key,
|
||||
required this.buttonItems,
|
||||
required this.anchors,
|
||||
}) : children = null;
|
||||
|
||||
/// Create an instance of [AdaptiveTextSelectionToolbar] with the default
|
||||
/// children for an editable field.
|
||||
///
|
||||
/// If an on* callback parameter is null, then its corresponding button will
|
||||
/// not be built.
|
||||
///
|
||||
/// These callbacks are called when their corresponding button is activated
|
||||
/// and only then. For example, `onPaste` is called when the user taps the
|
||||
/// "Paste" button in the context menu and not when the user pastes with the
|
||||
/// keyboard.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.new}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable}
|
||||
AdaptiveTextSelectionToolbar.editable({
|
||||
super.key,
|
||||
required ClipboardStatus clipboardStatus,
|
||||
required VoidCallback? onCopy,
|
||||
required VoidCallback? onCut,
|
||||
required VoidCallback? onPaste,
|
||||
required VoidCallback? onSelectAll,
|
||||
required VoidCallback? onLookUp,
|
||||
required VoidCallback? onSearchWeb,
|
||||
required VoidCallback? onShare,
|
||||
required VoidCallback? onLiveTextInput,
|
||||
required this.anchors,
|
||||
}) : children = null,
|
||||
buttonItems = EditableText.getEditableButtonItems(
|
||||
clipboardStatus: clipboardStatus,
|
||||
onCopy: onCopy,
|
||||
onCut: onCut,
|
||||
onPaste: onPaste,
|
||||
onSelectAll: onSelectAll,
|
||||
onLookUp: onLookUp,
|
||||
onSearchWeb: onSearchWeb,
|
||||
onShare: onShare,
|
||||
onLiveTextInput: onLiveTextInput,
|
||||
);
|
||||
|
||||
/// Create an instance of [AdaptiveTextSelectionToolbar] with the default
|
||||
/// children for an [EditableText].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.new}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable}
|
||||
AdaptiveTextSelectionToolbar.editableText({
|
||||
super.key,
|
||||
required EditableTextState editableTextState,
|
||||
}) : children = null,
|
||||
buttonItems = editableTextState.contextMenuButtonItems,
|
||||
anchors = editableTextState.contextMenuAnchors;
|
||||
|
||||
/// Create an instance of [AdaptiveTextSelectionToolbar] with the default
|
||||
/// children for selectable, but not editable, content.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.new}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText}
|
||||
AdaptiveTextSelectionToolbar.selectable({
|
||||
super.key,
|
||||
required VoidCallback onCopy,
|
||||
required VoidCallback onSelectAll,
|
||||
required VoidCallback? onShare,
|
||||
required SelectionGeometry selectionGeometry,
|
||||
required this.anchors,
|
||||
}) : children = null,
|
||||
buttonItems = SelectableRegion.getSelectableButtonItems(
|
||||
selectionGeometry: selectionGeometry,
|
||||
onCopy: onCopy,
|
||||
onSelectAll: onSelectAll,
|
||||
onShare: onShare,
|
||||
);
|
||||
|
||||
/// Create an instance of [AdaptiveTextSelectionToolbar] with the default
|
||||
/// children for a [SelectableRegion].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.new}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editable}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.editableText}
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.selectable}
|
||||
AdaptiveTextSelectionToolbar.selectableRegion({
|
||||
super.key,
|
||||
required SelectableRegionState selectableRegionState,
|
||||
}) : children = null,
|
||||
buttonItems = selectableRegionState.contextMenuButtonItems,
|
||||
anchors = selectableRegionState.contextMenuAnchors;
|
||||
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// The [ContextMenuButtonItem]s that will be turned into the correct button
|
||||
/// widgets for the current platform.
|
||||
/// {@endtemplate}
|
||||
final List<ContextMenuButtonItem>? buttonItems;
|
||||
|
||||
/// The children of the toolbar, typically buttons.
|
||||
final List<Widget>? children;
|
||||
|
||||
/// {@template flutter.material.AdaptiveTextSelectionToolbar.anchors}
|
||||
/// The location on which to anchor the menu.
|
||||
/// {@endtemplate}
|
||||
final TextSelectionToolbarAnchors anchors;
|
||||
|
||||
/// Returns the default button label String for the button of the given
|
||||
/// [ContextMenuButtonType] on any platform.
|
||||
static String getButtonLabel(
|
||||
BuildContext context,
|
||||
ContextMenuButtonItem buttonItem,
|
||||
) {
|
||||
if (buttonItem.label != null) {
|
||||
return buttonItem.label!;
|
||||
}
|
||||
|
||||
switch (Theme.of(context).platform) {
|
||||
case TargetPlatform.iOS:
|
||||
case TargetPlatform.macOS:
|
||||
return CupertinoTextSelectionToolbarButton.getButtonLabel(
|
||||
context,
|
||||
buttonItem,
|
||||
);
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
assert(debugCheckHasMaterialLocalizations(context));
|
||||
final MaterialLocalizations localizations = MaterialLocalizations.of(
|
||||
context,
|
||||
);
|
||||
return switch (buttonItem.type) {
|
||||
ContextMenuButtonType.cut => localizations.cutButtonLabel,
|
||||
ContextMenuButtonType.copy => localizations.copyButtonLabel,
|
||||
ContextMenuButtonType.paste => localizations.pasteButtonLabel,
|
||||
ContextMenuButtonType.selectAll => localizations.selectAllButtonLabel,
|
||||
ContextMenuButtonType.delete =>
|
||||
localizations.deleteButtonTooltip.toUpperCase(),
|
||||
ContextMenuButtonType.lookUp => localizations.lookUpButtonLabel,
|
||||
ContextMenuButtonType.searchWeb => localizations.searchWebButtonLabel,
|
||||
ContextMenuButtonType.share => localizations.shareButtonLabel,
|
||||
ContextMenuButtonType.liveTextInput =>
|
||||
localizations.scanTextButtonLabel,
|
||||
ContextMenuButtonType.custom => '',
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns a List of Widgets generated by turning [buttonItems] into the
|
||||
/// default context menu buttons for the current platform.
|
||||
///
|
||||
/// This is useful when building a text selection toolbar with the default
|
||||
/// button appearance for the given platform, but where the toolbar and/or the
|
||||
/// button actions and labels may be custom.
|
||||
///
|
||||
/// {@tool dartpad}
|
||||
/// This sample demonstrates how to use `getAdaptiveButtons` to generate
|
||||
/// default button widgets in a custom toolbar.
|
||||
///
|
||||
/// ** See code in examples/api/lib/material/context_menu/editable_text_toolbar_builder.2.dart **
|
||||
/// {@end-tool}
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar.getAdaptiveButtons], which is the
|
||||
/// Cupertino equivalent of this class and builds only the Cupertino
|
||||
/// buttons.
|
||||
static Iterable<Widget> getAdaptiveButtons(
|
||||
BuildContext context,
|
||||
List<ContextMenuButtonItem> buttonItems,
|
||||
) {
|
||||
switch (Theme.of(context).platform) {
|
||||
case TargetPlatform.iOS:
|
||||
return buttonItems.map((ContextMenuButtonItem buttonItem) {
|
||||
return CupertinoTextSelectionToolbarButton.buttonItem(
|
||||
buttonItem: buttonItem,
|
||||
);
|
||||
});
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.android:
|
||||
final buttons = <Widget>[];
|
||||
for (var i = 0; i < buttonItems.length; i++) {
|
||||
final ContextMenuButtonItem buttonItem = buttonItems[i];
|
||||
buttons.add(
|
||||
TextSelectionToolbarTextButton(
|
||||
padding: TextSelectionToolbarTextButton.getPadding(
|
||||
i,
|
||||
buttonItems.length,
|
||||
),
|
||||
onPressed: buttonItem.onPressed,
|
||||
alignment: AlignmentDirectional.centerStart,
|
||||
child: Text(getButtonLabel(context, buttonItem)),
|
||||
),
|
||||
);
|
||||
}
|
||||
return buttons;
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
return buttonItems.map((ContextMenuButtonItem buttonItem) {
|
||||
return DesktopTextSelectionToolbarButton.text(
|
||||
context: context,
|
||||
onPressed: buttonItem.onPressed,
|
||||
text: getButtonLabel(context, buttonItem),
|
||||
);
|
||||
});
|
||||
case TargetPlatform.macOS:
|
||||
return buttonItems.map((ContextMenuButtonItem buttonItem) {
|
||||
return CupertinoDesktopTextSelectionToolbarButton.text(
|
||||
onPressed: buttonItem.onPressed,
|
||||
text: getButtonLabel(context, buttonItem),
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// If there aren't any buttons to build, build an empty toolbar.
|
||||
if ((children ?? buttonItems)?.isEmpty ?? true) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final List<Widget> resultChildren = children != null
|
||||
? children!
|
||||
: getAdaptiveButtons(context, buttonItems!).toList();
|
||||
|
||||
switch (Theme.of(context).platform) {
|
||||
case TargetPlatform.iOS:
|
||||
return CupertinoTextSelectionToolbar(
|
||||
anchorAbove: anchors.primaryAnchor,
|
||||
anchorBelow: anchors.secondaryAnchor == null
|
||||
? anchors.primaryAnchor
|
||||
: anchors.secondaryAnchor!,
|
||||
children: resultChildren,
|
||||
);
|
||||
case TargetPlatform.android:
|
||||
return TextSelectionToolbar(
|
||||
anchorAbove: anchors.primaryAnchor,
|
||||
anchorBelow: anchors.secondaryAnchor == null
|
||||
? anchors.primaryAnchor
|
||||
: anchors.secondaryAnchor!,
|
||||
children: resultChildren,
|
||||
);
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
return DesktopTextSelectionToolbar(
|
||||
anchor: anchors.primaryAnchor,
|
||||
children: resultChildren,
|
||||
);
|
||||
case TargetPlatform.macOS:
|
||||
return CupertinoDesktopTextSelectionToolbar(
|
||||
anchor: anchors.primaryAnchor,
|
||||
children: resultChildren,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,240 +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_for_file: prefer_initializing_formals
|
||||
|
||||
/// @docImport 'package:flutter/material.dart';
|
||||
library;
|
||||
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/editable_text.dart';
|
||||
import 'package:flutter/cupertino.dart'
|
||||
hide EditableText, EditableTextState, CupertinoAdaptiveTextSelectionToolbar;
|
||||
import 'package:flutter/foundation.dart' show defaultTargetPlatform;
|
||||
import 'package:flutter/rendering.dart';
|
||||
|
||||
/// The default Cupertino context menu for text selection for the current
|
||||
/// platform with the given children.
|
||||
///
|
||||
/// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.platforms}
|
||||
/// Builds the mobile Cupertino context menu on all mobile platforms, not just
|
||||
/// iOS, and builds the desktop Cupertino context menu on all desktop platforms,
|
||||
/// not just MacOS. For a widget that builds the native-looking context menu for
|
||||
/// all platforms, see [AdaptiveTextSelectionToolbar].
|
||||
/// {@endtemplate}
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [AdaptiveTextSelectionToolbar], which does the same thing as this widget
|
||||
/// but for all platforms, not just the Cupertino-styled platforms.
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar.getAdaptiveButtons], which builds
|
||||
/// the Cupertino button Widgets for the current platform given
|
||||
/// [ContextMenuButtonItem]s.
|
||||
class CupertinoAdaptiveTextSelectionToolbar extends StatelessWidget {
|
||||
/// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the
|
||||
/// given [children].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar.buttonItems], which takes a list
|
||||
/// of [ContextMenuButtonItem]s instead of [children] widgets.
|
||||
/// {@endtemplate}
|
||||
/// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable}
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar.editable], which builds the
|
||||
/// default Cupertino children for an editable field.
|
||||
/// {@endtemplate}
|
||||
/// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText}
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar.editableText], which builds the
|
||||
/// default Cupertino children for an [EditableText].
|
||||
/// {@endtemplate}
|
||||
/// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable}
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar.selectable], which builds the
|
||||
/// Cupertino children for content that is selectable but not editable.
|
||||
/// {@endtemplate}
|
||||
const CupertinoAdaptiveTextSelectionToolbar({
|
||||
super.key,
|
||||
required this.children,
|
||||
required this.anchors,
|
||||
}) : buttonItems = null;
|
||||
|
||||
/// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] whose
|
||||
/// children will be built from the given [buttonItems].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// {@template flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new}
|
||||
/// * [CupertinoAdaptiveTextSelectionToolbar.new], which takes the children
|
||||
/// directly as a list of widgets.
|
||||
/// {@endtemplate}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable}
|
||||
const CupertinoAdaptiveTextSelectionToolbar.buttonItems({
|
||||
super.key,
|
||||
required this.buttonItems,
|
||||
required this.anchors,
|
||||
}) : children = null;
|
||||
|
||||
/// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the
|
||||
/// default children for an editable field.
|
||||
///
|
||||
/// If a callback is null, then its corresponding button will not be built.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [AdaptiveTextSelectionToolbar.editable], which is similar to this but
|
||||
/// includes Material and Cupertino toolbars.
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable}
|
||||
CupertinoAdaptiveTextSelectionToolbar.editable({
|
||||
super.key,
|
||||
required ClipboardStatus clipboardStatus,
|
||||
required VoidCallback? onCopy,
|
||||
required VoidCallback? onCut,
|
||||
required VoidCallback? onPaste,
|
||||
required VoidCallback? onSelectAll,
|
||||
required VoidCallback? onLookUp,
|
||||
required VoidCallback? onSearchWeb,
|
||||
required VoidCallback? onShare,
|
||||
required VoidCallback? onLiveTextInput,
|
||||
required this.anchors,
|
||||
}) : children = null,
|
||||
buttonItems = EditableText.getEditableButtonItems(
|
||||
clipboardStatus: clipboardStatus,
|
||||
onCopy: onCopy,
|
||||
onCut: onCut,
|
||||
onPaste: onPaste,
|
||||
onSelectAll: onSelectAll,
|
||||
onLookUp: onLookUp,
|
||||
onSearchWeb: onSearchWeb,
|
||||
onShare: onShare,
|
||||
onLiveTextInput: onLiveTextInput,
|
||||
);
|
||||
|
||||
/// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the
|
||||
/// default children for an [EditableText].
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [AdaptiveTextSelectionToolbar.editableText], which is similar to this
|
||||
/// but includes Material and Cupertino toolbars.
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.selectable}
|
||||
CupertinoAdaptiveTextSelectionToolbar.editableText({
|
||||
super.key,
|
||||
required EditableTextState editableTextState,
|
||||
}) : children = null,
|
||||
buttonItems = editableTextState.contextMenuButtonItems,
|
||||
anchors = editableTextState.contextMenuAnchors;
|
||||
|
||||
/// Create an instance of [CupertinoAdaptiveTextSelectionToolbar] with the
|
||||
/// default children for selectable, but not editable, content.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [AdaptiveTextSelectionToolbar.selectable], which is similar to this but
|
||||
/// includes Material and Cupertino toolbars.
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.new}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.buttonItems}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editable}
|
||||
/// {@macro flutter.cupertino.CupertinoAdaptiveTextSelectionToolbar.editableText}
|
||||
CupertinoAdaptiveTextSelectionToolbar.selectable({
|
||||
super.key,
|
||||
required VoidCallback onCopy,
|
||||
required VoidCallback onSelectAll,
|
||||
required SelectionGeometry selectionGeometry,
|
||||
required this.anchors,
|
||||
}) : children = null,
|
||||
buttonItems = SelectableRegion.getSelectableButtonItems(
|
||||
selectionGeometry: selectionGeometry,
|
||||
onCopy: onCopy,
|
||||
onSelectAll: onSelectAll,
|
||||
onShare: null, // See https://github.com/flutter/flutter/issues/141775.
|
||||
);
|
||||
|
||||
/// {@macro flutter.material.AdaptiveTextSelectionToolbar.anchors}
|
||||
final TextSelectionToolbarAnchors anchors;
|
||||
|
||||
/// The children of the toolbar, typically buttons.
|
||||
final List<Widget>? children;
|
||||
|
||||
/// The [ContextMenuButtonItem]s that will be turned into the correct button
|
||||
/// widgets for the current platform.
|
||||
final List<ContextMenuButtonItem>? buttonItems;
|
||||
|
||||
/// Returns a List of Widgets generated by turning [buttonItems] into the
|
||||
/// default context menu buttons for Cupertino on the current platform.
|
||||
///
|
||||
/// This is useful when building a text selection toolbar with the default
|
||||
/// button appearance for the given platform, but where the toolbar and/or the
|
||||
/// button actions and labels may be custom.
|
||||
///
|
||||
/// Does not build Material buttons. On non-Apple platforms, Cupertino buttons
|
||||
/// will still be used, because the Cupertino library does not access the
|
||||
/// Material library. To get the native-looking buttons on every platform,
|
||||
/// use [AdaptiveTextSelectionToolbar.getAdaptiveButtons] in the Material
|
||||
/// library.
|
||||
///
|
||||
/// See also:
|
||||
///
|
||||
/// * [AdaptiveTextSelectionToolbar.getAdaptiveButtons], which is the Material
|
||||
/// equivalent of this class and builds only the Material buttons. It
|
||||
/// includes a live example of using `getAdaptiveButtons`.
|
||||
static Iterable<Widget> getAdaptiveButtons(
|
||||
BuildContext context,
|
||||
List<ContextMenuButtonItem> buttonItems,
|
||||
) {
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.fuchsia:
|
||||
case TargetPlatform.iOS:
|
||||
return buttonItems.map((ContextMenuButtonItem buttonItem) {
|
||||
return CupertinoTextSelectionToolbarButton.buttonItem(
|
||||
buttonItem: buttonItem,
|
||||
);
|
||||
});
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
case TargetPlatform.macOS:
|
||||
return buttonItems.map((ContextMenuButtonItem buttonItem) {
|
||||
return CupertinoDesktopTextSelectionToolbarButton.buttonItem(
|
||||
buttonItem: buttonItem,
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// If there aren't any buttons to build, build an empty toolbar.
|
||||
if ((children ?? buttonItems)?.isEmpty ?? true) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final List<Widget> resultChildren =
|
||||
children ?? getAdaptiveButtons(context, buttonItems!).toList();
|
||||
|
||||
switch (defaultTargetPlatform) {
|
||||
case TargetPlatform.android:
|
||||
case TargetPlatform.iOS:
|
||||
case TargetPlatform.fuchsia:
|
||||
return CupertinoTextSelectionToolbar(
|
||||
anchorAbove: anchors.primaryAnchor,
|
||||
anchorBelow: anchors.secondaryAnchor ?? anchors.primaryAnchor,
|
||||
children: resultChildren,
|
||||
);
|
||||
case TargetPlatform.linux:
|
||||
case TargetPlatform.windows:
|
||||
case TargetPlatform.macOS:
|
||||
return CupertinoDesktopTextSelectionToolbar(
|
||||
anchor: anchors.primaryAnchor,
|
||||
children: resultChildren,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,6 @@ import 'dart:math' as math;
|
||||
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
|
||||
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/cupertino/adaptive_text_selection_toolbar.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/cupertino/spell_check_suggestions_toolbar.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/editable_text.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/spell_check.dart';
|
||||
@@ -24,7 +23,6 @@ import 'package:flutter/cupertino.dart'
|
||||
CupertinoSpellCheckSuggestionsToolbar,
|
||||
EditableTextContextMenuBuilder,
|
||||
SystemContextMenu,
|
||||
CupertinoAdaptiveTextSelectionToolbar,
|
||||
SpellCheckConfiguration,
|
||||
TextSelectionGestureDetectorBuilderDelegate,
|
||||
TextSelectionGestureDetectorBuilder,
|
||||
@@ -827,8 +825,9 @@ class CupertinoRichTextField extends StatefulWidget {
|
||||
editableTextState: editableTextState,
|
||||
);
|
||||
}
|
||||
return CupertinoAdaptiveTextSelectionToolbar.editableText(
|
||||
editableTextState: editableTextState,
|
||||
return CupertinoAdaptiveTextSelectionToolbar.buttonItems(
|
||||
anchors: editableTextState.contextMenuAnchors,
|
||||
buttonItems: editableTextState.contextMenuButtonItems,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -5950,7 +5950,7 @@ class EditableTextState extends State<EditableText>
|
||||
child: Builder(
|
||||
builder: (BuildContext context) {
|
||||
return TextFieldTapRegion(
|
||||
groupId: widget.groupId,
|
||||
// groupId: widget.groupId,
|
||||
onTapOutside: _hasFocus
|
||||
? (PointerDownEvent event) => _onTapOutside(context, event)
|
||||
: null,
|
||||
|
||||
@@ -4,15 +4,10 @@
|
||||
|
||||
// ignore_for_file: prefer_initializing_formals
|
||||
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/adaptive_text_selection_toolbar.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/editable_text.dart';
|
||||
import 'package:flutter/cupertino.dart' hide EditableText, EditableTextState;
|
||||
import 'package:flutter/material.dart'
|
||||
hide
|
||||
EditableText,
|
||||
EditableTextState,
|
||||
AdaptiveTextSelectionToolbar,
|
||||
SpellCheckSuggestionsToolbar;
|
||||
hide EditableText, EditableTextState, SpellCheckSuggestionsToolbar;
|
||||
import 'package:flutter/scheduler.dart';
|
||||
import 'package:flutter/services.dart'
|
||||
show SelectionChangedCause, SuggestionSpan;
|
||||
|
||||
@@ -13,7 +13,6 @@ library;
|
||||
|
||||
import 'dart:ui' as ui show BoxHeightStyle, BoxWidthStyle;
|
||||
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/adaptive_text_selection_toolbar.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/controller.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/cupertino/spell_check_suggestions_toolbar.dart';
|
||||
import 'package:PiliPlus/common/widgets/flutter/text_field/cupertino/text_field.dart';
|
||||
@@ -42,7 +41,6 @@ import 'package:flutter/material.dart'
|
||||
EditableText,
|
||||
EditableTextState,
|
||||
EditableTextContextMenuBuilder,
|
||||
AdaptiveTextSelectionToolbar,
|
||||
SystemContextMenu,
|
||||
SpellCheckSuggestionsToolbar,
|
||||
SpellCheckConfiguration,
|
||||
@@ -905,8 +903,9 @@ class RichTextField extends StatefulWidget {
|
||||
editableTextState: editableTextState,
|
||||
);
|
||||
}
|
||||
return AdaptiveTextSelectionToolbar.editableText(
|
||||
editableTextState: editableTextState,
|
||||
return AdaptiveTextSelectionToolbar.buttonItems(
|
||||
anchors: editableTextState.contextMenuAnchors,
|
||||
buttonItems: editableTextState.contextMenuButtonItems,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user