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

flutter简单自定义跟随手指滑动的横向指示器

在这里插入图片描述

ScrollController _scrollController = ScrollController();double _scrollIndicatorWidth = 60.w;//指示器的长度double _maxScrollPaddingValue = 30.w;//指示器中蓝条可移动的最大距离double _scrollPaddingValue = 0.0;//指示器中蓝条左边距(蓝条移动距离)void initState() {super.initState();_scrollController.addListener(() {setState(() {final double scrollOffset = _scrollController.offset;final double? scrollableExtent = _scrollController.position.maxScrollExtent;//  final double viewportExtent = _scrollController?.position?.viewportDimension;if(scrollableExtent != null){_scrollPaddingValue = (scrollOffset / scrollableExtent) * _maxScrollPaddingValue;}if(_scrollPaddingValue > _maxScrollPaddingValue){_scrollPaddingValue = _maxScrollPaddingValue;}});});}
void dispose() {_scrollController.dispose();super.dispose();}//横向tab布局
_goodsTabBar() {if(_goodsCategoryList.isNotEmpty){return Column(children: [SingleChildScrollView(controller: _scrollController,scrollDirection: Axis.horizontal,child:TabBar(controller: _tabController,// tabs的长度超出屏幕宽度后,TabBar,是否可滚动isScrollable: true,// 设置tab文字的类型labelStyle: TextStyle(fontSize: 24.sp, letterSpacing: 1),// 设置tab选中得颜色labelColor: JadeColors.green_7,labelPadding: EdgeInsets.symmetric(horizontal: 10.w),// 设置tab未选中的颜色unselectedLabelColor: JadeColors.grey,// 设置tab未选中时文字的类型unselectedLabelStyle: TextStyle(fontSize: 24.sp, letterSpacing: 1),indicatorWeight: 0.01,indicatorColor: JadeColors.grey_2,tabs: _goodsCategoryList.asMap().entries.map((entry){int index = entry.key;GoodsCategoryBean value = entry.value;bool isSelect = _tabController!.index == index;return Column(children: [Container(margin: EdgeInsets.only(top: 40.w,bottom: 10.w),width: 90.w,height: 90.w,decoration: BoxDecoration(border: isSelect? Border.all(color: JadeColors.green_7, width: 0.8): null,borderRadius: BorderRadius.circular(5),),child: Image.asset(value.iconPath ?? PathConfig.aTuiLogo),),Text(value.name!)],);}).toList(),)),_scrollIndicator()],);}else{return SizedBox.shrink();}}
http://www.xdnf.cn/news/9396.html

相关文章:

  • Django数据库连接报错 django.db.utils.NotSupportedError: MySQL 8 or later is required
  • 代码输出题:异步事件循环
  • Spring boot 策略模式
  • YOLOv5 详解:从原理到实战的全方位解析
  • 35. 自动化测试开发之使用oracle连接池实现oracle数据库操作
  • 34. 自动化测试开发之使用mysql异步连接池实现mysql数据库操作
  • 碰一碰系统源码搭建
  • DH加密详解
  • 什么是PLM系统?PLM主要功能有哪些?2025主流PLM系统介绍
  • 第五十五节:综合项目实践-实时人脸美化滤镜
  • 三轴云台之积分分离PID控制算法篇
  • 【通关文件操作(上)】--文件的意义和概念,二进制文件和文本文件,文件的打开和关闭,文件的顺序读写
  • 鸿蒙运动开发实战:打造 Keep 式轨迹播放效果
  • Java Stream API 终止操作的详细解析
  • QML之Canvas
  • 数组名的大小理解
  • <b> 与 <span> 等行内元素添加 margin-top 或 margin-bottom 不生效问题
  • CarPropertyService 介绍
  • 【FAQ】spring boot 3 集成 nacos
  • pgsql 查看每张表大小
  • 创建vue项目
  • 3D Web轻量化引擎HOOPS Communicator实时协作功能深度解析
  • 小黑黑大模型应用日常摸索中:初次使用langchain智能体调用工具,准备继续深入
  • 题解——相交链表(力扣160 easy)
  • Java研学-MybatisPlus(三)
  • 磁盘管理练习题
  • 《Python基础》第1期:人生苦短,我用Python
  • Java基础 5.27
  • Oracle初识
  • 遗传算法简明指南:思路解析与C++实现