Flutter - ListView wrapped by Listener

kq0g1dla  于 2023-06-07  发布在  Flutter
关注(0)|答案(2)|浏览(170)
Listener(
        onPointerUp: (event) {
                   LogUtil.v('++++++onPointerUp++++');
},
        child: ListView.builder(
               itemCount:10,
                itemBuilder:(context, index) {
                   return GestureDetector(
                          onTap:() {
                              LogUtil.v('++++++GestureDetector++++');
                          },
                          child:Container(
                             height:200
                          )
                    )
                }
))

当我单击列表视图项目时,打印'+GestureDetector','++onPointerUp'也被打印。如何使'+onPointerUp'不打印?

v2g6jxz6

v2g6jxz61#

如果您不需要监听器中的日志,为什么不删除以下行:

LogUtil.v('++++++onPointerUp++++');
x6yk4ghg

x6yk4ghg2#

也许像这样的事情是有可能的

bool tapped = false;

Listener(
        onPointerUp: (event) {
                 if (!tapped ) {
                   LogUtil.v('++++++onPointerUp++++');
                 } else {
                   tapped = false;
                 }
},
        child: ListView.builder(
               itemCount:10,
                itemBuilder:(context, index) {
                   return GestureDetector(
                          onTap:() {
                              tapped = true;
                              LogUtil.v('++++++GestureDetector++++');
                          },
                          child:Container(
                             height:200
                          )
                    )
                }
))

相关问题