我通过添加Ctrl+C和Ctrl+V来防止文本字段(颤振网)中的复制粘贴
enableInteractiveSelection: false,
toolbarOptions: ToolbarOptions(
copy: false,
cut: false,
paste: false,
selectAll: false,
),但是,仍然可以通过以下方法复制粘贴,

有可能预防吗?
发布于 2022-11-24 11:55:29
如果用户右键单击textfield,则取消焦点,甚至禁用它:
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,
),
),
);
}发布于 2022-11-24 11:51:32
在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>它将防止鼠标右键单击。
https://stackoverflow.com/questions/74559760
复制相似问题