在flutter中禁用粘贴并从textformfield中选择所有功能按钮

Far*_*ana 9 android dart flutter

我想禁用所有与复制、粘贴和全选相关的功能textformfield。我有一个密码字段,它可以接受键盘提示并默认粘贴数据,但是当我执行诸如调用登录服务之类的操作时,密码字段出错了。

 TextFormField(
      obscureText: true,
      style: styleText,
      textInputAction: TextInputAction.done,
      controller: _passwordController,
      focusNode: _passwordFocus,
      onFieldSubmitted: (term){
        _passwordFocus.unfocus();
      },
      keyboardType: TextInputType.text,
      validator: validatePassword,
      decoration: InputDecoration(
          focusedBorder: border,
          border: border,
          enabledBorder: border,
          hintStyle: styleText,
          hintText: 'Password'),
      onSaved: (String val) {
        _password = val;
      },
    ),
Run Code Online (Sandbox Code Playgroud)

Neh*_*waj 31

您可以使用enableinteractiveSelection : false禁用复制/粘贴。

TextFormField(
          enableInteractiveSelection: false,
          obscureText: true,
          style: styleText,
          textInputAction: TextInputAction.done,
          controller: _passwordController,
          focusNode: _passwordFocus,
          onFieldSubmitted: (term){
            _passwordFocus.unfocus();
          },
          keyboardType: TextInputType.text,
          validator: validatePassword,
          decoration: InputDecoration(
              focusedBorder: border,
              border: border,
              enabledBorder: border,
              hintStyle: styleText,
              hintText: 'Password'),
          onSaved: (String val) {
            _password = val;
          },
        ),
Run Code Online (Sandbox Code Playgroud)

  • 对于想要禁用复制粘贴但不想移动插入符号的人,请使用工具栏选项。如果你得到 bool 不是 Toolbaroptions 的子类型,请升级你的 flutter 版本。但升级flutter版本时要小心 (2认同)

Muh*_*fay 14

您可以尝试一下这disable any particular option并不是所有的选项。

 TextFormField(
      toolbarOptions: ToolbarOptions(
        copy: true,
        cut: true,
        paste: false,
        selectAll: false,
      ),
    ...
    ..
    .
Run Code Online (Sandbox Code Playgroud)

  • 有什么方法可以完全禁用粘贴(您可以从键盘菜单粘贴)? (3认同)