Skip to content

burhanaksendir/selection_controls_example

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

selection_controls_example

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

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Dart 97.5%
  • Swift 1.2%
  • HTML 1.2%
  • Other 0.1%