当前位置: 首页 > news >正文

flutter在包含ListVIew的滚动列表页面中监听手势

列表控件内部页有监听事件,使用GestureDetector监听有冲突,所以使用NotificationListener。

示例中增加了Listener监听手指滑动方向

//手指的偏移量double _startDx = 0.0;double _endDx = 0.0;double _dy = 0.0;//标签栏高度double _tabBarHeight = 80.w;//标签栏刷新事件late StateSetter _setTabBarState;//偏移阈值double _listerOffsetThreshold = 40.0;_body() {return NotificationListener<ScrollNotification>(onNotification: (dynamic scrollNotification) {if (scrollNotification is ScrollUpdateNotification &&scrollNotification.depth == 0) {// 滚动且是列表滚动的时候//  print('滑动偏移量:${scrollNotification.metrics.pixels}');}return true;},child: Listener(onPointerDown: (downPointer){_startDx = downPointer.position.dx;_dy = downPointer.position.dy;},onPointerMove: _onPointerMove,onPointerUp: _onPointerUp,child: Column(children: [// 头部分类列表_userShareTabBar(),// 推享文章列表Expand(child: ListView.builder(/// 列表)),],)));}_onPointerMove(PointerMoveEvent movePointer){//向下滑动。if (movePointer.position.dy - _dy > 0) {if (movePointer.position.dy - _dy > _listerOffsetThreshold) {print('向下滑动');_setTabBarState((){_tabBarHeight = 80.w;});}} else {if (-(movePointer.position.dy - _dy) > _listerOffsetThreshold) {print('向上滑动');_setTabBarState((){_tabBarHeight = 0.0;});}}}_onPointerUp(PointerUpEvent upPointer){_endDx = upPointer.position.dx;//向下滑动if (upPointer.position.dy - _dy > 0) {if (upPointer.position.dy - _dy > _listerOffsetThreshold) {print('向下滑动');_setTabBarState((){_tabBarHeight = 80.w;});}} else {if (-(upPointer.position.dy - _dy) > _listerOffsetThreshold) {print('向上滑动');_setTabBarState((){_tabBarHeight = 0.0;});}}final double _deltaX = _endDx - _startDx;if(_deltaX.abs() > _listerOffsetThreshold){if(_tabBarHeight == 0.0){_setTabBarState((){_tabBarHeight = 80.w;});}}}//在当前页面中需要局部刷新的模块
_userShareTabBar() {//使用StatefulBuilder在手势监听事件中调用局部的刷新(使用setState会刷新整个页面造成卡顿)return StatefulBuilder(builder: (context, setStateBuilder) {_setTabBarState = setStateBuilder;return AnimatedContainer(duration: Duration(milliseconds: 200),height: _tabBarHeight,child: UserShareTabBarPage());});}
http://www.dtcms.com/a/391206.html

相关文章:

  • Redis 三种集群模式详解
  • 打开hot100
  • Ant-Design Table中使用 AStatisticCountdown倒计时,鼠标在表格上移动时倒计时被重置
  • Linux crontab 定时任务工具使用
  • 阿里云RDS mysql8数据本地恢复,与本地主从同步(容器中)
  • 记录一次mysql启动失败问题解决
  • LeetCode算法练习:35.搜索插入位置
  • (1) 为什么推荐tauri框架
  • 嵌入式面试高频(八)!!!C++语言(嵌入式八股文,嵌入式面经)
  • Spring AI开发指导-工具调用
  • Linux 基本命令超详细解释第二期 | touch | cat | more | cp | mv | rm | which | find
  • [x-cmd] 安装指南
  • Altium Designer(AD24)原理图Move移动功能详细介绍图文教程
  • 部署java程序,服务器报403 Forbidden 问题的终极解决方案
  • 【LeetCode】链表经典问题解析:环形、回文与相交
  • 电磁超材料及其领域应用优势
  • STM32与Modbus RTU协议实战开发指南-fc3ab6a453
  • ArrayList 与 LinkedList 深度对比:从原理到场景的全方位解析
  • Ubuntu和windows复制粘贴互通
  • 银行回单 OCR 识别:财务自动化的 “数据入口“
  • 深兰科技陈海波的AI破局之道:打造软硬一体综合竞争力|《中国经营报》专访
  • 面试经验之mysql高级问答深度解析
  • 高质量票据识别数据集:1000张收据图像+2141个商品标注,支持OCR模型训练与文档理解研究
  • 嵌入式音视频开发——FFmpeg入门
  • MySQL索引篇---B+树在索引中的工作原理
  • 强化学习训练-数据处理
  • VirtualBox为ubuntu系统设置共享文件夹
  • Python实战进阶》No.41: 使用 Streamlit 快速构建 ML 应用
  • Salesforce 执行顺序(Order of Execution)详解
  • Linux内核进程管理子系统有什么第五十七回 —— 进程主结构详解(53)