flutter_widget_from_html icon indicating copy to clipboard operation
flutter_widget_from_html copied to clipboard

Is has any way to set custom selection controls?

Open FiShelly opened this issue 3 years ago • 2 comments

Use case

Want to set custom selectable controls in htmlWidget, Is has any way?

FiShelly avatar Feb 09 '22 08:02 FiShelly

I think this can be done. It's not possible with the current version though.

daohoangson avatar Feb 10 '22 02:02 daohoangson

You can make your own widget factory and override the buildText method, something like this:

class _MyWidgetFactory extends WidgetFactory {

  @override
  Widget? buildText(BuildMetadata meta, TextStyleHtml tsh, InlineSpan text) {
    if (text is TextSpan) {
      return SelectableText.rich(
        text,
        maxLines: meta.maxLines > 0 ? meta.maxLines : null,
        selectionControls: _MyTextSelectionControls(), // replace with yours
        textAlign: tsh.textAlign ?? TextAlign.start,
        textDirection: tsh.textDirection,
        textScaleFactor: 1.0,
      );
    }

    return super.buildText(meta, tsh, text);
  }
}

daohoangson avatar May 01 '22 07:05 daohoangson