【问题标题】:Show pulsing cursor but do not open the keyboard when textfield is initialized初始化文本字段时显示脉冲光标但不打开键盘
【发布时间】:2019-11-01 16:26:58
【问题描述】:

我不希望键盘在我按下小部件时自动出现。但是,我想显示光标以指示该区域中有一个文本字段。我怎样才能做到这一点?

【问题讨论】:

    标签: flutter flutter-layout


    【解决方案1】:

    我只能想到一种解决方法。您可以将 FocusNode 添加到您的领域并听取更改。当字段获得焦点时,隐藏键盘。

      final FocusNode fn = FocusNode();
      fn.addListener(() {
        // You can control here whether or not you want to hide automatically shown keyboard
        if (fn.hasFocus) {
          // Hiding the keyboard 
          SystemChannels.textInput.invokeMethod('TextInput.hide');
        }
      });
    
      ...
      // Pass the focus node to text field:
      TextField(
        focusNode: fn
      );
    

    不过,我还没有测试过。

    【讨论】:

      猜你喜欢
      • 2021-04-02
      • 1970-01-01
      • 1970-01-01
      • 2021-09-16
      • 2011-05-10
      • 2016-06-11
      • 2021-06-19
      • 2011-09-17
      • 1970-01-01
      相关资源
      最近更新 更多