加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

dart – 以编程方式关注InputField并打开键盘

发布时间:2020-12-14 14:51:02 所属栏目:百科 来源:网络整理
导读:我有一种情况,我需要以编程方式专注于 InputField(例如响应按钮按下). 我正在使用Focus.moveTo功能;但是,即使InputField处于聚焦状态(出现闪烁的光标),键盘也不会启动. 似乎最好的解决方案是在_InputFieldState中调用RequestKeyboard()函数,但这是私有的. 实
我有一种情况,我需要以编程方式专注于 InputField(例如响应按钮按下).

我正在使用Focus.moveTo功能;但是,即使InputField处于聚焦状态(出现闪烁的光标),键盘也不会启动.

似乎最好的解决方案是在_InputFieldState中调用RequestKeyboard()函数,但这是私有的.

实现这一目标的最佳方法是什么?

以下是显示工作流程的代码示例:

class InputFieldWrapper extends StatefulWidget {

  @override
  _InputFieldWrapperState createState() => new _InputFieldWrapperState();
}


class _InputFieldWrapperState extends State<InputFieldWrapper> {

  InputValue _currentInput = new InputValue(text: 'hello');

  // GlobalKey for the InputField so we can focus on it
  GlobalKey<EditableTextState> _inputKey = new GlobalKey<EditableTextState>();

  @override
  Widget build(BuildContext context) {
    return new Column(
      children: [
        // Button that should focus on the InputField when pressed
        new IconButton(
          icon: new Icon(Icons.message),onPressed: () {
            Focus.moveTo(_inputKey);
          },),// InputField that should be focused when pressing the Button
        new InputField(
          value: _currentInput,key: _inputKey,onChanged: (InputValue input) {
            setState(() {
              _currentInput = input;
            });
          }
        ),],);
  }
}

解决方法

这被认定是一个错误,并在 #7985被跟踪.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读