【问题标题】:Is there an efficient way to focus to the next textformfield? (Flutter)有没有一种有效的方法可以专注于下一个 textformfield? (扑)
【发布时间】:2021-10-05 10:02:00
【问题描述】:

我有一个包含近 300 个文本字段的应用程序,我一直在使用 autofocus 和 textinputaction 属性转到下一个文本字段。它适用于带有普通键盘的文本字段。但是当我使用数字键盘进入表单的下一部分时,这个属性变得不可靠并且并不总是关注下一个文本字段。我听说使用 Focusnode 类将是一个解决方案,但这将需要制作 300 个焦点节点并实现它们。

我想知道你们中是否有人知道另一种以更可靠和更有效的方式专注于下一个领域的方法。

感谢您的回答!

示例: [1]:https://i.stack.imgur.com/AZjBz.gif [2]:https://i.stack.imgur.com/kEOnw.png [3]:https://i.stack.imgur.com/wXeGf.png

【问题讨论】:

    标签: flutter performance textfield


    【解决方案1】:

    textInputAction: TextInputAction.next 应该可以正常工作

    【讨论】:

      【解决方案2】:

      这就是你可以解决的方法。

      Form(
        child: SingleChildScrollView(
          padding: EdgeInsets.symmetric(horizontal: 16.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            children: <Widget>[
              TextFormField(
                textInputAction: TextInputAction.next, // Keyboard with Next arrow
                autofocus: true, // Place cursor on this field at start up
                decoration: InputDecoration(labelText: "First field"),
              ),
              TextFormField(
                textInputAction: TextInputAction.next,
                decoration: InputDecoration(labelText: "Second field"),
              ),
            ],
          ),
        ),
      );
      

      【讨论】:

      • 感谢您的反馈!我已经试过了。它对我不起作用。我不得不使用focusnodes,现在它工作得很好。不过还是感谢您的关注!
      猜你喜欢
      • 2019-09-10
      • 1970-01-01
      • 1970-01-01
      • 2020-01-21
      • 2011-06-18
      • 2021-05-16
      • 1970-01-01
      • 2021-10-10
      • 1970-01-01
      相关资源
      最近更新 更多