buildToolbar method

  1. @override
Widget buildToolbar(
  1. BuildContext context,
  2. Rect globalEditableRegion,
  3. double textLineHeight,
  4. Offset selectionMidpoint,
  5. List<TextSelectionPoint> endpoints,
  6. TextSelectionDelegate delegate,
  7. ClipboardStatusNotifier clipboardStatus,
  8. Offset? lastSecondaryTapDownPosition,
)
override

Builder for material-style copy/paste text selection toolbar.

Implementation

@override
Widget buildToolbar(
  BuildContext context,
  Rect globalEditableRegion,
  double textLineHeight,
  Offset selectionMidpoint,
  List<TextSelectionPoint> endpoints,
  TextSelectionDelegate delegate,
  ClipboardStatusNotifier clipboardStatus,
  Offset? lastSecondaryTapDownPosition,
) {
  return TextSelectionToolbar(
    anchorAbove: lastSecondaryTapDownPosition! + const Offset(0, -24),
    anchorBelow: lastSecondaryTapDownPosition + const Offset(0, 24),
    toolbarBuilder: (context, child) => Container(
      clipBehavior: Clip.hardEdge,
      decoration: BoxDecoration(
        color: Colors.white,
        border: Border.all(color: Colors.black12),
        borderRadius: BorderRadius.circular(50),
      ),
      child: child,
    ),
    children: <Widget>[
      TextSelectionToolbarTextButton(
        child: const Icon(Icons.cut_rounded, size: 22, color: Colors.black87),
        padding: const EdgeInsets.all(8.0).copyWith(left: 18),
        onPressed: canCut(delegate) ? () => handleCut(delegate) : null,
      ),
      TextSelectionToolbarTextButton(
        child:
            const Icon(Icons.copy_rounded, size: 22, color: Colors.black87),
        padding: const EdgeInsets.all(8.0),
        onPressed: canCopy(delegate)
            ? () => handleCopy(delegate, clipboardStatus)
            : null,
      ),
      TextSelectionToolbarTextButton(
        child:
            const Icon(Icons.paste_rounded, size: 22, color: Colors.black87),
        padding: const EdgeInsets.all(8.0),
        onPressed: canPaste(delegate) ? () => handlePaste(delegate) : null,
      ),
      //
      // Bold
      //
      TextSelectionToolbarTextButton(
        child: const Icon(
          Icons.format_bold_rounded,
          size: 22,
          color: Colors.black87,
        ),
        padding: const EdgeInsets.all(8.0),
        onPressed: () => _handleBold(delegate),
      ),

      //
      // Italic
      //
      TextSelectionToolbarTextButton(
        child: const Icon(
          Icons.format_italic_rounded,
          size: 22,
          color: Colors.black87,
        ),
        padding: const EdgeInsets.all(8.0),
        onPressed: () => _handleItalic(delegate),
      ),

      //
      // Underline
      //
      TextSelectionToolbarTextButton(
        child: const Icon(
          Icons.format_underline_rounded,
          size: 22,
          color: Colors.black87,
        ),
        padding: const EdgeInsets.all(8.0),
        onPressed: () => _handleUnderLine(delegate),
      ),

      //
      // strick through
      //
      TextSelectionToolbarTextButton(
        child: const Icon(
          Icons.format_strikethrough_rounded,
          size: 22,
          color: Colors.black87,
        ),
        padding: const EdgeInsets.all(8.0).copyWith(right: 18),
        onPressed: () => _handleStrickThrough(delegate),
      ),
    ],
  );
}