Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/dart/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Dart 以编程方式关注InputField并打开键盘_Dart_Flutter - Fatal编程技术网

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

Dart 以编程方式关注InputField并打开键盘,dart,flutter,Dart,Flutter,我有一种情况,我需要以编程的方式将注意力集中在一个问题上(例如,为了响应按钮的按下) 我正在使用这个函数;但是,即使InputField已聚焦(光标闪烁),键盘也不会打开 似乎最好的解决方案是调用_InputFieldState中的函数,但这是私有的 实现这一目标的最佳方式是什么 以下是显示工作流的代码示例: class InputFieldWrapper extends StatefulWidget { @override _InputFieldWrapperState create

我有一种情况,我需要以编程的方式将注意力集中在一个问题上(例如,为了响应按钮的按下)

我正在使用这个函数;但是,即使InputField已聚焦(光标闪烁),键盘也不会打开

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

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

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

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;
            });
          }
        ),
      ],
    );
  }
}
类InputFieldWrapper扩展StatefulWidget{
@凌驾
_InputFieldWrapperState createState()=>new_InputFieldWrapperState();
}
类_InputFieldWrapperState扩展状态{
InputValue_currentInput=新的InputValue(文本:“hello”);
//GlobalKey用于输入字段,以便我们可以关注它
GlobalKey _inputKey=new GlobalKey();
@凌驾
小部件构建(构建上下文){
返回新列(
儿童:[
//按下时应聚焦于输入字段的按钮
新图标按钮(
图标:新图标(Icons.message),
已按下:(){
Focus.moveTo(_inputKey);
},
),
//按下按钮时应聚焦的输入字段
新输入字段(
值:_currentInput,
键:_inputKey,
一旦更改:(输入值输入){
设置状态(){
_电流输入=输入;
});
}
),
],
);
}
}

这被确定为一个bug,正在跟踪。

看起来像个bug。提交了一个bug: