【问题标题】:Flutter - Identifying when the user touches outside of the Textformfield after finishing typingFlutter - 识别用户在完成输入后何时触摸 Textformfield 之外
【发布时间】:2021-06-07 08:44:47
【问题描述】:

当用户在 Textformfield 中输入文本时,每个字符都会触发 onChanged 回调,如果用户在完成输入后按下回车键,则会触发 onFieldSubmitted 回调。但是,我想要不同于 onChanged 和 onFieldSubmitted 的行为。

(下面我所说的outside是指背景或任何其他UI元素)

有没有人知道一种方法来识别用户在完成输入后何时触摸了 Textformfield 的外部? 我要问的与 onFieldSubmitted 的行为非常相似。 但没有按回车键

谢谢!

【问题讨论】:

  • 将脚手架包裹在手势检测器中

标签: flutter flutter-android


【解决方案1】:

使用 GestureDetector 检测屏幕上的点击:

body: GestureDetector(
      behavior: HitTestBehavior.opaque,
      onTap: () => _onFieldSubmitted(), // call to the function
      child: ...  //  your Widgets is here
),

【讨论】:

    【解决方案2】:

    使用手势检测器检测任何小部件外的点击

    如果我是正确的,当用户在widger外部按下时您需要放下键盘,使用此代码来执行此操作

     GestureDetector(
      onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
      child: Scaffold...
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-02-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-09-19
      • 2022-10-21
      • 1970-01-01
      相关资源
      最近更新 更多