flutter中GestureDetector不触发手势的问题

搭建的一个ListView,这是自定义item,在item上添加了点击手势,发现了一个奇怪的问题,如果点击外层的Container空白部分,手势不会触发,只有点击到其他Widget才会触发手势,但是如果我给外层的Container加点属性比如更改一下Container的颜色或者加个圆角,这时候点击Container也可以触发,(加宽度高度依然不触发)。amazing,是不是默认的Container没有用户交互???
先不管了,手势不触发的问题找到了,闲下来再找原因...

Widget getListItem(BuildContext context, int index){
    return GestureDetector(
      onTap: (){
        print("触发了");
      },
      child: Container(
        // color: Colors.white,//不加点属性,就没有点击效果
        child: Stack(
          children: [
            Positioned(
              child: Container(
                margin: EdgeInsets.only(top: 15, bottom: 15, left: 25),
                width: 90,
                color: Colors.black,
              ),
            ),

            Positioned(
              right: 15,
              top: 15,
              child: Container(
                child: Image.asset("assets/order/paid.png", width: 56, height: 56,),
              ),
            ),

            Positioned(
                left: 130,
                right: 90,
                top: 35,
                child: Text(
                  "支払い済",
                  style: TextStyle(
                      fontSize: 14,
                      color: HexColor.fromHex("#00082A"),

                  ),
                  overflow: TextOverflow.ellipsis,//超出部分显示省略号
                  maxLines: 2,
                )
            ),

            Positioned(
                left: 130,
                right: 90,
                bottom: 40,
                child: Text(
                  "有効期限:2022-07-18",
                  style: TextStyle(
                      fontSize: 12,
                      color: HexColor.fromHex("#8F97B2")
                  ),
                )
            ),

            Positioned(
                left: 130,
                right: 90,
                bottom: 15,
                child: Text(
                  "作成時間:2022-01-18",
                  style: TextStyle(
                    fontSize: 12,
                    color: HexColor.fromHex("#8F97B2")
                  ),
                )
            ),
          ],
        ),
      ),
    );
  }
}

——————————------————————————————————————
给GestureDetector 添加属性behavior: HitTestBehavior.opaque,

GestureDetector(
    behavior: HitTestBehavior.opaque,
)

手势透传的原因,改个Container颜色,behavior属性却可以不用设,flutter还是有点怪的

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容