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

标签 dart flutter

我有一种情况需要以编程方式关注 InputField (例如响应按钮按下)。

我正在使用 Focus.moveTo功能;但是,即使 InputField 已获得焦点(出现闪烁的光标),键盘也不会出现。

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

最好的方法是什么?

这是一个显示工作流程的代码示例:

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 进行跟踪.

关于dart - 以编程方式关注 InputField 并打开键盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42122236/

相关文章:

user-interface - 如何将listView转换为GridView抖动?

firebase - 如何在 firebase flutter 中向现有 map 添加新数据

android - 使用本地移动库调用 Dart

flutter - 为什么我不能在flutter中使用可为空的类型

Flutter 在发布 PNG 文件时收到来自 Fastapi 的 422 响应

ios - Flutter video_player 从头开始​​重新启动视频

dart - 没有 AppBar 的 Flutter TabBar

drop-down-menu - 如何在 flutter 中实现下拉列表?

flutter - 'Future<String>' 的实例而不是显示值

ios - 未使用AnchorType.top加载的Google Admob标语广告