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

网站建设和网络推广天津网站制作系统

网站建设和网络推广,天津网站制作系统,亚马逊营业执照怎么办理,网站建设开票应该开哪个行业flutter 自定义TabBar 【top 0 级别】 前言一、基础widget二、tab 标签三、barView总结 前言 在日常开发中,tab 标签选项,是一个我们特别常用的一个组件了,往往我们在一个项目中,有很多地方会使用到它,每次单独去写&am…

flutter 自定义TabBar 【top 0 级别】

  • 前言
  • 一、基础widget
  • 二、tab 标签
  • 三、barView
  • 总结


前言

在这里插入图片描述

在日常开发中,tab 标签选项,是一个我们特别常用的一个组件了,往往我们在一个项目中,有很多地方会使用到它,每次单独去写,真的是太繁琐,这里我会定义一个通用的tab 选择器,喜欢的朋友可以拿去试试


一、基础widget

直接先上代码

class YSTabbarWidget extends StatefulWidget {/// tabListfinal List<String> tabs;/// 是否可滑动  (居左)final bool? isScrollable;/// 高亮文字大小final double? textSize;/// 非高亮文字大小final double? unTextSize;/// 小线颜色final Color? tabColors;/// 文字高亮颜色final Color? labelColor;/// 非高亮文字颜色final Color? unselectedLabelColor;/// controller 必传final TabController? controller;/// tab间距final double? horizontal;/// 下划线颜色,根据文字大小  根据tab大小final double lineBottom;final TabBarIndicatorSize? indicatorSize;/// page Listfinal List<Widget> tabbarViewList;final Function(int)? didSelectIndex;/// 是否显示分割线final bool? showLine;const YSTabbarWidget({Key? key,required this.tabs,required this.controller,this.tabbarViewList = const [],this.unselectedLabelColor,this.isScrollable,this.textSize = 16.0,this.unTextSize = 16.0,this.tabColors,this.labelColor,this.horizontal,this.lineBottom = 0,this.indicatorSize,this.didSelectIndex,this.showLine = true}): super(key: key);State<YSTabbarWidget> createState() => _YSTabbarWidgetState();
}class _YSTabbarWidgetState extends State<YSTabbarWidget> {void initState() {// TODO: implement initStatesuper.initState();}Widget build(BuildContext context) {return Column(// mainAxisAlignment: MainAxisAlignment.start,crossAxisAlignment: CrossAxisAlignment.start,mainAxisSize: MainAxisSize.min,children: [getTabbarWidget(),widget.showLine == true? Container(height: 0.5,color: const Color(0xffe5e5e5),): Container(),getTabbarViewWidget(),],);}
}

通过上面的代码,我们可以看到,这里定义了很多属性,当然每个属性都有注释进行解释,这里就不赘述了。

二、tab 标签

上面的代码中,我们可以看到这个getTabbarWidget() 自定义的组件,它就是我们需要自定义的一个tab 按钮部分了

Widget getTabbarWidget() {return TabBar(isScrollable: widget.isScrollable ?? false,controller: widget.controller,indicatorColor: widget.tabColors ?? Colours.app_main,// indicatorWeight:10,indicatorSize: widget.indicatorSize ?? TabBarIndicatorSize.label,indicatorPadding: const EdgeInsets.only(left: 0),indicator: UnderlineTabIndicator(insets: EdgeInsets.only(bottom: widget.lineBottom),borderRadius: const BorderRadius.all(Radius.circular(1)),borderSide: BorderSide(color: widget.tabColors ?? Colours.app_main,width: 2, //高度),),labelColor: widget.labelColor ?? Colours.app_main,unselectedLabelColor: widget.unselectedLabelColor ?? Colours.textBlack3,labelPadding:EdgeInsets.symmetric(horizontal: widget.horizontal ?? 20.w),labelStyle: TextStyle(fontSize: widget.textSize,fontWeight: FontWeight.w600,),unselectedLabelStyle: TextStyle(fontSize: widget.unTextSize),onTap: (value) {if (widget.didSelectIndex != null) {widget.didSelectIndex!(value);}},tabs: widget.tabs.map<Tab>((String tab) {return Tab(text: tab,);}).toList());
}

结合篇头的代码及注释,我们可以简单的理解上面的每一行代码。这里需要说明的是,如果你想自定义tab 的样式或者是其他的一些功能需求,都可以直接在上面的代码中进行修改调整。

有人可能会有疑问,代码的中的showLine到底判断的是啥?

widget.showLine == true? Container(height: 0.5,color: const Color(0xffe5e5e5),): Container(),

其实它就是一个分界线,可以根据自己的需求进行调整样式,也可以根据showLine 参数,进行判断是否需要添加分界线。

三、barView

既然我们封装的使用通用的tabbar,那么barview 肯定是必不可少的,接来下我们看看getTabbarViewWidget() 这个自定义的组件。

Widget getTabbarViewWidget() {if(widget.tabbarViewList.isNotEmpty){return Expanded(child: TabBarView(controller: widget.controller,children: widget.tabbarViewList,),);}else{return Container();}
}

getTabbarViewWidget 的代码就比较少了,简单的来说,就是穿一个个上下文controller, 再传入你的widget 就可以了。

看到这里,你学废了没?


总结

简简单单一个widget,复制粘贴直接用,废话不多说,啥?没有写怎么调用?不知道怎么调用,你还是去看看前面的文章吧。

http://www.dtcms.com/wzjs/370444.html

相关文章:

  • 毕设做网站有什么题目seo优化实训报告
  • 深圳龙霸网站建设物三惠州百度seo地址
  • 网上在线购物系统谷歌seo 优化
  • 企业管理的官方网站有哪些链接推广平台
  • 制作介绍的网站模板免费广州seo
  • 东莞建设网网上平台西安官网seo技术
  • wordpress网站关键词西安seo搜推宝
  • 四川新闻今日头条消息seo营销软件
  • 简洁文章类网站想要网站导航正式推广
  • 多点网络网站制作系统百度seo优化哪家好
  • 摄影个人网站模板域名注册
  • 企业级网站开发与部署企业推广平台排行榜
  • 做网站宽度和长度布局百度建站云南服务中心
  • 宁波做百度网站南宁网站推广排名
  • 保定网站建设培训班长春seo排名外包
  • 河北建设工程网站互联网广告投放
  • 做网站要什么技术网址制作
  • 如何选择网站建设流程浙江新手网络推广
  • wordpress建立网站会员卡营销策划方案
  • 谷歌wordpress建站360优化大师软件
  • 三种常用的网站设计软件北大青鸟培训机构靠谱吗
  • wordpress 分类目录seo插件搜索引擎营销与seo优化
  • 百度竞价网站谁做品牌营销活动策划方案
  • 来宾建设工程造价网站seo服务外包费用
  • 制作一个网站的费用抖音推广合作方式
  • 企业网站 多网站推广免费友情链接网
  • 好看云在线网站模板下载 迅雷下载 迅雷下载地址semir是什么牌子
  • 北京免费网站建设创建网站的流程是什么
  • 网站排名下降什么是市场营销
  • 做网站买流量新闻最新热点