How to make copyable Text Widget in Flutter?

前端 未结 5 1224
闹比i
闹比i 2020-12-04 16:54

When long tab on Text widget, a tooltip show up with \'copy\'. When click on the \'copy\' the text content should copy to system clipboard.

The following will copy t

5条回答
  •  时光说笑
    2020-12-04 17:13

    There is also list of properties it in SelectableText to enable option copy, paste, selectAll, cut

            child: Center(
                child: SelectableText('Hello Flutter Developer',
                    cursorColor: Colors.red,
                    showCursor: true,
                    toolbarOptions: ToolbarOptions(
                    copy: true,
                    selectAll: true,
                    cut: false,
                    paste: false
                    ),
                    style: Theme.of(context).textTheme.body2)
                ),
    

    SelectableText widget

            const SelectableText(
                this.data, {
                Key key,
                this.focusNode,
                this.style,
                this.strutStyle,
                this.textAlign,
                this.textDirection,
                this.showCursor = false,
                this.autofocus = false,
                ToolbarOptions toolbarOptions,
                this.maxLines,
                this.cursorWidth = 2.0,
                this.cursorRadius,
                this.cursorColor,
                this.dragStartBehavior = DragStartBehavior.start,
                this.enableInteractiveSelection = true,
                this.onTap,
                this.scrollPhysics,
                this.textWidthBasis,
            })
    

提交回复
热议问题