美文网首页
flutter GestureDetector嵌套TextFie

flutter GestureDetector嵌套TextFie

作者: CrystalStudio | 来源:发表于2020-07-22 15:26 被阅读0次

GestureDetector的behavior有三个类型

enum HitTestBehavior {
  /// Targets that defer to their children receive events within their bounds
  /// only if one of their children is hit by the hit test.
  deferToChild,

  /// Opaque targets can be hit by hit tests, causing them to both receive
  /// events within their bounds and prevent targets visually behind them from
  /// also receiving events.
  opaque,

  /// Translucent targets both receive events within their bounds and permit
  /// targets visually behind them to also receive events.
  translucent,
}

默认是deferToChild,只有当children可以接收点击事件才能响应点击。

  • 原因:
    业务场景是点击textfield跳转到新页面,所以套一层GestureDetector来响应,然后将TextField的enabled设置为false,所以默认情况下响应不了点击。

  • 解决方法:
    将GestureDetector的behavior属性修改为behavior: HitTestBehavior.opaque即可。

相关文章

网友评论

      本文标题:flutter GestureDetector嵌套TextFie

      本文链接:https://www.haomeiwen.com/subject/rxftlktx.html