SelectionArea(
contextMenuBuilder: (context, editableTextState) {
return AdaptiveTextSelectionToolbar.buttonItems(
anchors: editableTextState.contextMenuAnchors,
buttonItems: <ContextMenuButtonItem>[
ContextMenuButtonItem(
onPressed: () {},
type: ContextMenuButtonType.copy,
),
ContextMenuButtonItem(
onPressed: () {},
type: ContextMenuButtonType.lookUp,
),
ContextMenuButtonItem(
onPressed: () {},
type: ContextMenuButtonType.searchWeb,
),
ContextMenuButtonItem(
onPressed: () {},
type: ContextMenuButtonType.share,
),
],
);
},
child: HtmlWidget(
articleDetail?.body
)
)
我想知道如何实现按下时的每个选项
我尝试获取选定的文本以实现复制到剪贴板。但未能获取选定的文本。
非常感谢任何帮助。谢谢。
您可以依靠操作系统来帮助您。 只需使用 Flutter 中的 SelectableText 小部件即可:
const SelectableText(
'Hello! How are you?',
textAlign: TextAlign.center,
style: TextStyle(fontWeight: FontWeight.bold),
)
或者如果您想要富文本,请使用:
const SelectableText.rich(
TextSpan(
text: 'Hello', // default text style
children: <TextSpan>[
TextSpan(text: ' beautiful ', style: TextStyle(fontStyle: FontStyle.italic)),
TextSpan(text: 'world', style: TextStyle(fontWeight: FontWeight.bold)),
],
),
)