如何更改 ContextMenuButtonItem 的样式 我不想为了更改 Android 按钮的 2 种样式而重做整个功能。 也许主题数据中这些按钮的样式发生了变化?
TextField(
contextMenuBuilder: (context, editableTextState) {
final value = editableTextState.textEditingValue;
final List<ContextMenuButtonItem> buttonItems = [
ContextMenuButtonItem(
onPressed: () {},
type: ContextMenuButtonType.custom,
)
];
return AdaptiveTextSelectionToolbar.buttonItems(
buttonItems: buttonItems, anchors: editableTextState.contextMenuAnchors);
},
)
我创建了一个单独的类,在其中制作了自己的小部件。但我无法连接 List 和 List
class _MyContextMenu extends StatelessWidget {
const _MyContextMenu({
required this.anchor,
required this.children,
required this.contextMenuButtonItems,
});
final Offset anchor;
final List<Widget> children;
final List<ContextMenuButtonItem> contextMenuButtonItems;
@override
Widget build(BuildContext context) {
contextMenuButtonItems.insert(0, Container() as ContextMenuButtonItem);
return Stack(
children: [
Positioned(
height: 34,
top: anchor.dy + 38,
left: anchor.dx - 24,
child: Card(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(2)),
child: Center(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
...children,
...contextMenuButtonItems.map((item) => YourWidget(item)),
],
),
),
),
),
],
);
}
}
查看 flutter 文档来更改样式
https://api.flutter.dev/flutter/material/TextField/contextMenuBuilder.html