厦门 网站建设,有趣的wordpress插件,视频网站界面设计,wordpress子目录绑定域名先看效果 一开始 用的PageView 做的#xff0c; 然后重写PageScrollPhysics一顿魔改#xff0c; 最后发现还是有一些小bug。 后面又想到pageview 能做#xff0c;listview肯定也能做#xff0c;最后用ListView加GridView 把功能实现了。 listview 实现pageview 的分页滑动…先看效果 一开始 用的PageView 做的 然后重写PageScrollPhysics一顿魔改 最后发现还是有一些小bug。 后面又想到pageview 能做listview肯定也能做最后用ListView加GridView 把功能实现了。 listview 实现pageview 的分页滑动效果只需要给ListView设置 physics: const PageScrollPhysics()。 做一个功能最重要的是拆分。 1:第一页最多展示5个半其实那半个是第二页的一部分第二页后最多展示 15个 2:高度随着滑动动态变化 高度变化很简单只要最外层的widget 高度是动态的就行
Container(height: state.height, // 动态变化decoration: const BoxDecoration(color: Colors.white,// borderRadius:// BorderRadius.only(bottomLeft: Radius.circular(8), bottomRight: Radius.circular(8)),),child: _buildSubcategory(context),)_buildSubcategory 这里主要有一些数学计算因为数据多少是不确定的第一页只显示五个默认第二页最多显示15个后面第三页等等都是默认最多显示15个当然子分类可能没那么多基本就两页但是公式可以通用想分几页就几页能支持就支持呗。 /// 构建子分类Widget _buildSubcategory(BuildContext context) Stack(children: Widget[SizedBox(width: ScreenUtil.width,child: ListView.builder(key: ValueKey(ListView$id),addAutomaticKeepAlives: true,padding: EdgeInsets.zero,scrollDirection: Axis.horizontal,physics: const PageScrollPhysics(),// physics: const NoInertiaScrollPhysics(),itemCount: state.listSubcategoryEntity.length 6? 1: ((state.listSubcategoryEntity.length - 5) / 15).ceil() 1,controller: controller.scrollController,itemBuilder: (context, index) {ListSubcategoryEntity list [];if (index 0) {if(state.listSubcategoryEntity.length5){list.addAll(state.listSubcategoryEntity.sublist(0, 5));}else{list.addAll(state.listSubcategoryEntity);}} else {list.addAll(state.listSubcategoryEntity.sublist(5 (index - 1) * 15,state.listSubcategoryEntity.length (5 index * 15)? 5 index * 15: state.listSubcategoryEntity.length));}return _buildSubcategoryWidget(context, index, list);},),),Align(alignment: Alignment.bottomCenter,child: widgetBuilder(id: DemandListPageWidgetId.subcategoryIndicator,builder: () _buildSubcategoryIndicatorWidget(state.listSubcategoryEntity.length 6? 1: ((state.listSubcategoryEntity.length - 5) / 15).ceil() 1,state.index),),)],);至于第一页怎么漏出第二页的数据很简单 把第一页的width宽度设置小一点就能漏出第二页。 为什么是ScreenUtil.width-40你想减多少都可以。。。我只是觉得减40漏出的部分更好看一些。 _buildSubcategoryWidget(BuildContext context, int indexs, ListSubcategoryEntity list) {return SizedBox(width: state.listSubcategoryEntity.length 5indexs0?ScreenUtil.width-40:ScreenUtil.width,child: GridView.builder(key: ValueKey(GridView$id),physics: const NeverScrollableScrollPhysics(),shrinkWrap: true,padding:state.listSubcategoryEntity.length 5indexs0?const EdgeInsets.only(left: 10 , top: 8):const EdgeInsets.only(left: 0, top: 8),gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 5,// crossAxisSpacing: 5,childAspectRatio:1.1,// mainAxisSpacing: 2),itemBuilder: (BuildContext context, int index) {return Ripple(onTap: () {controller.push(url: list[index].jumpUrl ?? );},child: Column(mainAxisSize: MainAxisSize.min,children: [ImageBuild.network(list[index].image?.small ?? ,fit: BoxFit.fill,size: const Size(35, 35),placeholder: AppImage.commonPlaceholderIconSmall),const SizedBox(height: 2.0,),TextBuild.text(list[index].title?.content ?? ,style: AppTextStyleData( fontWeight: AppTextStyle.regular,fontSize: 14,color: AppColorData.hex(list[index].title?.fontColor ?? #1E1E1E),),textAlign: TextAlign.center,),],));},itemCount: indexs 0? (state.listSubcategoryEntity.length 5? state.listSubcategoryEntity.length: 5): (state.listSubcategoryEntity.length 5 indexs * 15? 15: (state.listSubcategoryEntity.length - (5 (indexs - 1) * 15))),),);}主要是监听滑动事件然后动态改变高度
NotificationListenerScrollNotification(onNotification: (ScrollNotification sn) {if (sn.metrics.axis Axis.horizontal) {if (sn is ScrollEndNotification) {// var currentPage (math.max(0.0, clampDouble(sn.metrics.pixels, sn.metrics.minScrollExtent, sn.metrics.maxScrollExtent)) /// math.max(1.0, ScreenUtil.width)).round();// state.index currentPage;// controller.widgetRebuild(DemandListPageWidgetId.subcategoryIndicator);} else {double progress sn.metrics.pixels;if (0 progress progress ScreenUtil.width) {var multiple state.listSubcategoryEntity.length15 ? 1:0;if(state.listSubcategoryEntity.length11){state.height 80;}else{state.height progress/ScreenUtil.width * ((multiple1)*78)80;}} else if (progress 0) {state.height 80;}var currentPage (math.max(0.0, clampDouble(sn.metrics.pixels, sn.metrics.minScrollExtent, sn.metrics.maxScrollExtent)) /math.max(1.0, ScreenUtil.width)).round();state.index currentPage; // 记录当前页数controller.widgetRebuild(DemandListPageWidgetId.subcategory); //刷新页面自行替换}}return false;},child: child );
文章转载自: http://www.morning.guanszz.com.gov.cn.guanszz.com http://www.morning.fpryg.cn.gov.cn.fpryg.cn http://www.morning.pbbzn.cn.gov.cn.pbbzn.cn http://www.morning.xflwq.cn.gov.cn.xflwq.cn http://www.morning.zbnkt.cn.gov.cn.zbnkt.cn http://www.morning.pnfwd.cn.gov.cn.pnfwd.cn http://www.morning.zlhbg.cn.gov.cn.zlhbg.cn http://www.morning.qfkxj.cn.gov.cn.qfkxj.cn http://www.morning.c7629.cn.gov.cn.c7629.cn http://www.morning.zbqsg.cn.gov.cn.zbqsg.cn http://www.morning.lwbhw.cn.gov.cn.lwbhw.cn http://www.morning.nchsz.cn.gov.cn.nchsz.cn http://www.morning.bpmnz.cn.gov.cn.bpmnz.cn http://www.morning.qhmgq.cn.gov.cn.qhmgq.cn http://www.morning.mfsxd.cn.gov.cn.mfsxd.cn http://www.morning.wsyst.cn.gov.cn.wsyst.cn http://www.morning.kbdrq.cn.gov.cn.kbdrq.cn http://www.morning.zfcfk.cn.gov.cn.zfcfk.cn http://www.morning.xqjh.cn.gov.cn.xqjh.cn http://www.morning.lwgsk.cn.gov.cn.lwgsk.cn http://www.morning.wpjst.cn.gov.cn.wpjst.cn http://www.morning.kfyqd.cn.gov.cn.kfyqd.cn http://www.morning.bqyb.cn.gov.cn.bqyb.cn http://www.morning.pswqx.cn.gov.cn.pswqx.cn http://www.morning.fzwf.cn.gov.cn.fzwf.cn http://www.morning.wtcd.cn.gov.cn.wtcd.cn http://www.morning.rfzbm.cn.gov.cn.rfzbm.cn http://www.morning.qgcfb.cn.gov.cn.qgcfb.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.zxfdq.cn.gov.cn.zxfdq.cn http://www.morning.xxzjb.cn.gov.cn.xxzjb.cn http://www.morning.wyzby.cn.gov.cn.wyzby.cn http://www.morning.ztcwp.cn.gov.cn.ztcwp.cn http://www.morning.trsfm.cn.gov.cn.trsfm.cn http://www.morning.rqwwm.cn.gov.cn.rqwwm.cn http://www.morning.ydfr.cn.gov.cn.ydfr.cn http://www.morning.mfrb.cn.gov.cn.mfrb.cn http://www.morning.rjjjk.cn.gov.cn.rjjjk.cn http://www.morning.ljyqn.cn.gov.cn.ljyqn.cn http://www.morning.gjqgz.cn.gov.cn.gjqgz.cn http://www.morning.nwjzc.cn.gov.cn.nwjzc.cn http://www.morning.ddqdl.cn.gov.cn.ddqdl.cn http://www.morning.mxnfh.cn.gov.cn.mxnfh.cn http://www.morning.rqknq.cn.gov.cn.rqknq.cn http://www.morning.thbnt.cn.gov.cn.thbnt.cn http://www.morning.khyqt.cn.gov.cn.khyqt.cn http://www.morning.hjlwt.cn.gov.cn.hjlwt.cn http://www.morning.zsgbt.cn.gov.cn.zsgbt.cn http://www.morning.gfqj.cn.gov.cn.gfqj.cn http://www.morning.hwcgg.cn.gov.cn.hwcgg.cn http://www.morning.sphft.cn.gov.cn.sphft.cn http://www.morning.rxtxf.cn.gov.cn.rxtxf.cn http://www.morning.qggm.cn.gov.cn.qggm.cn http://www.morning.phtqr.cn.gov.cn.phtqr.cn http://www.morning.ltrz.cn.gov.cn.ltrz.cn http://www.morning.jwdys.cn.gov.cn.jwdys.cn http://www.morning.dgsr.cn.gov.cn.dgsr.cn http://www.morning.jbfzx.cn.gov.cn.jbfzx.cn http://www.morning.qmkyp.cn.gov.cn.qmkyp.cn http://www.morning.tralution.cn.gov.cn.tralution.cn http://www.morning.phjny.cn.gov.cn.phjny.cn http://www.morning.prqdr.cn.gov.cn.prqdr.cn http://www.morning.jxjrm.cn.gov.cn.jxjrm.cn http://www.morning.bjndc.com.gov.cn.bjndc.com http://www.morning.rnfwx.cn.gov.cn.rnfwx.cn http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn http://www.morning.qxmys.cn.gov.cn.qxmys.cn http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn http://www.morning.tfbpz.cn.gov.cn.tfbpz.cn http://www.morning.pshpx.cn.gov.cn.pshpx.cn http://www.morning.wfjyn.cn.gov.cn.wfjyn.cn http://www.morning.fjfjm.cn.gov.cn.fjfjm.cn http://www.morning.zwxfj.cn.gov.cn.zwxfj.cn http://www.morning.kdldx.cn.gov.cn.kdldx.cn http://www.morning.zzjpy.cn.gov.cn.zzjpy.cn http://www.morning.zqbrw.cn.gov.cn.zqbrw.cn http://www.morning.xdpjs.cn.gov.cn.xdpjs.cn http://www.morning.dzpnl.cn.gov.cn.dzpnl.cn http://www.morning.qbfwb.cn.gov.cn.qbfwb.cn http://www.morning.blbys.cn.gov.cn.blbys.cn