【问题标题】:Disable paste and select all function button from textformfield in flutter在flutter中禁用粘贴并从textformfield中选择所有功能按钮
【发布时间】:2019-07-18 13:04:09
【问题描述】:

我想禁用所有与复制、粘贴和全选相关的功能,按 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;
      },
    ),

【问题讨论】:

  • 简单的方法就是禁用你的TextFormField的长点击事件
  • @NileshRathod 如何访问文本字段的longpress。

标签: android dart flutter


【解决方案1】:

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

【讨论】:

  • 有没有办法禁用复制粘贴但不能禁用插入符号的移动?
  • 对于想要禁用复制粘贴但不想移动插入符号的人,请使用工具栏选项。如果你得到 bool 不是 Toolbaroptions 的子类型,则升级你的颤振版本。但是升级flutter版本时要小心
【解决方案2】:

你可以试试这个disable any particular option 不是所有的选项。

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

【讨论】:

  • 它在一定程度上有所帮助。您仍然可以通过键盘原生选项“粘贴”。
  • 有什么方法可以完全禁用粘贴(您可以从键盘菜单粘贴)?
猜你喜欢
  • 2021-10-11
  • 1970-01-01
  • 1970-01-01
  • 2021-04-07
  • 1970-01-01
  • 1970-01-01
  • 2017-07-01
  • 2020-12-09
  • 2011-07-13
相关资源
最近更新 更多