繁体   English   中英

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

[英]Disable paste and select all function button from textformfield in flutter

我想在 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;
      },
    ),

您可以使用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;
          },
        ),

您可以尝试disable any particular option而不是所有选项。

 TextFormField(
      toolbarOptions: ToolbarOptions(
        copy: true,
        cut: true,
        paste: false,
        selectAll: false,
      ),
    ...
    ..
    .

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM