【问题标题】:flutter TextField sticky, cursor jumps back to it when I finish with other items颤动TextField粘性,当我完成其他项目时光标跳回它
【发布时间】:2020-08-06 02:58:32
【问题描述】:

在我的新工作屏幕上,我有一个 About TextFormField 小部件,如果我在其中输入一些文本,然后继续与其他小部件进行交互,例如获取工作开始的时间,一旦我完成了这些小部件,光标跳回TextFormField,Flutter假设用户有未完成的事情。

如何告诉 Flutter 不要重新激活 TestField 小部件?保持光标不可见,并专注于其他地方?

我试过用谷歌搜索答案,毫无疑问,它就在那里,我只是没有词汇,但它让我认为它与专注有关。我尝试设置 autofocus: false,但不是这样。

      Column(children: <Widget>[
       TextFormField(
        style: Theme.of(context).textTheme.bodyText2,
        decoration: InputDecoration(
          labelStyle: Theme.of(context).textTheme.bodyText2,
          //errorText: _showValidationError ? 'Invalid number entered' : null,
          labelText: 'Comprehensive job description',
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(0.0),
          ),
        ),
        autofocus: false,
        keyboardType: TextInputType.multiline,
        onSaved: (String description) =>
            this.widget.job.description = description.trim(),
      ),
      RaisedButton(
        onPressed: () => _selectDate(context, startDate),
        child: Text('Select start date'),
      ),
      // TODO only show for certain categories
      CheckboxListTile(
        secondary: Icon(Icons.calendar_today),
        title: Text('To be completed the same day?'),
        subtitle: Text(showEndDatePicker == true
            ? "Must be completed same day."
            : "Could be completed in a few days."),
        value: showEndDatePicker ?? false,
        onChanged: (bool value) {
          setState(() {
            showEndDatePicker = value;
          });
        },
      ),
  Visibility(
    visible: !showEndDatePicker ?? false,
    child: RaisedButton(
      onPressed: () => _selectDate(context, endDate),
      child: Text('Select end date'),
    ),
  ),
   ]
);

如果我在 TextFormField 中键入一些内容,然后单击凸起的按钮,它会召唤一个日期选择器。完美的。但完成后,焦点会跳回 TextFormField,弹出键盘。用户可能已完成此字段。

让光标向后跳几个小部件,然后莫名其妙地弹出键盘是糟糕的用户体验,求助!

【问题讨论】:

  • 最好提供完整代码以便我们提供帮助。

标签: flutter focus textfield


【解决方案1】:

我遇到了类似的问题,并使用 UnfocusDisposition 解决了它。试试这个例子:unfocus method

【讨论】:

    猜你喜欢
    • 2023-03-04
    • 2019-07-15
    • 2021-05-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-30
    • 1970-01-01
    • 2023-03-03
    相关资源
    最近更新 更多