A repo that experiments with the missing features related to the text selection controls and context menus
final menu = CupertinoSelectionToolbar(
theme: CupertinoThemeData(),
actions: [
ContextMenuItem.sublist(title: Text('Format'), children: [
ContextMenuItem(
title: Icon(Icons.brush, size: 18),
onPressed: (menuController) {
final selection = menuController.textSelectionController?.selection;
highlightSelection(selection);
return true; // Return true to close the menu when pressed
},
),
ContextMenuItem(
title: Icon(Icons.format_bold, size: 18),
onPressed: (menuController) {
final selection = menuController.textSelectionController?.selection;
boldSelection(selection);
return true;
},
),
]),
TextSelectionContextMenuItem.copy(), // Default text selection items
TextSelectionContextMenuItem.selectAll(),
ContextMenuItem(
title: Text('Search'),
onPressed: (menuController) {
return true;
},
),
ContextMenuItem(
title: Text('Share'),
onPressed: (menuController) {
return true;
},
),
],
);
To use for text inside a TextField, SelectableText, TextFormField, CupertinoTextField:
TextField(
selectionControls: DefaultTextSelectionControls(
handle: CupertinoTextSelectionHandle(color: Colors.black),
toolbar: menu,
),
),
To display it when tapped on any widget.
ContextMenuButton(
child: Icon(Icons.menu),
menu: menu,
);
Custom items in text selection toolbar
Submenus
Context menus usable in text selection or any widget