1

I prevent copy paste in textformfield(Flutter web) using Ctrl+C and Ctrl+V by adding

enableInteractiveSelection: false,
toolbarOptions: ToolbarOptions(
  copy: false,
  cut: false,
  paste: false,
  selectAll: false,
),

But still, it is possible to copy-paste by the following method, enter image description here

Is it possible to prevent ?

Developer
  • 148
  • 8

2 Answers2

1

work around is, if user right click on textfield, unfocus, or even disable it:

Widget build(BuildContext context) {
        return SizedBox(
          width: 300,
          child: Listener(
            onPointerDown: (event){
              if(event.kind == PointerDeviceKind.mouse && event.buttons == kSecondaryMouseButton){
                print('yoo the user try to right click unfocus this so he cant paste');
                _focusNode.unfocus();
              }
            },
            child: TextField(
              enableInteractiveSelection: false,
              toolbarOptions: ToolbarOptions(
                paste: false
              ),
              onChanged: (data){
                print(data);
              },
              focusNode: _focusNode,
              controller: _textEditingController,
            ),
          ),
        );
      }
Sayyid J
  • 1,215
  • 1
  • 4
  • 18
0

Added the below code in index.html

<script type="text/javascript">
    document.oncontextmenu = new Function('return false')
    document.body.oncut = new Function('return false');
    document.body.oncopy = new Function('return false');
    document.body.onpaste = new Function('return false');
</script>

It will prevent right click of mouse.

Developer
  • 148
  • 8