The flutter (on desktop) shows this custom context menu for the text fields which is absolutely ugly:
Do you know of a way that this can be customized?
UPDATE
I actually found the answer. You have to implement a class based on TextSelectionControls
and give it to selectionControls
of the TextInputField. Also you can lookup the MaterialTextSelectionControls
which has a simple implementation to understand how it is done.
2
Answers
With Flutter 3.7 you can now create custom context menus anywhere in a Flutter app.
A
contextMenuBuilder
parameter has been added to many widgets (e.g.TextField
,CupertinoTextField
,SelectionArea
, etc.). You can return any widget you want fromcontextMenuBuilder
, including modifying the default platform-adaptive context menu.Example: (source)
This new feature works outside of text selection too by using
ContextMenuController
. You could, for example, create an Image widget that shows a Save button when right clicked or long pressed: (source)You can find more examples of custom context menus in:
Answer for 2023
This functionality was added in Flutter 3.7 (related Github comment).
See the official context menu sample repo here.