原文地址:https://www.cnblogs.com/upwgh/p/11369537.html

TabBar:Tab页的选项组件,默认为水平排列。

TabBarView:Tab页的内容容器,Tab页内容一般处理为随选项卡的改变而改变。

TabController:TabBar和TabBarView的控制器,它是关联这两个组件的桥梁。

TabBar组件常见属性
属性名 类型 说明
isScrollable bool 是否可以水平移动
tabs List<Widget> Tab选项列表
Tab组件常见属性
属性名 类型 说明
icon Widget Tab图标
text String Tab文本
TabBarView组件常见属性
属性名 类型 说明
controller TabController 指定视图的控制器
children List<Widget> 视图组件的child为一个列表,一个选项卡对应一个视图

上面我们说的TabController,与其并列的还有DefaultTabController,两者的区别是TabController一般放在有状态组件中使用,而DefaultTabController一般放在无状态组件中使用。

下面通过DefalutTabController来关联TabBar和TabBarView来实现一个Demo:

按 Ctrl+C 复制代码

按 Ctrl+C 复制代码

效果截图:

接下来分别看一下DefaultTabController、TabBar、TabBarView的构造函数有什么:

  • DefaultTabController
  const DefaultTabController({
Key key,
@required this.length,
this.initialIndex = 0,
@required this.child,
}) : assert(initialIndex != null),
super(key: key);
  • TabBar
  const TabBar({
Key key,
@required this.tabs,//显示的标签内容,一般使用Tab对象,也可以是其他Widget
this.controller,//TabController对象
this.isScrollable = false,//是否可以滚动
this.indicatorColor,//指示器颜色
this.indicatorWeight = 2.0,//指示器的高度
this.indicatorPadding = EdgeInsets.zero,//指示器底部的padding
this.indicator,//指示器decoration,例如边框等
this.indicatorSize,//指示器大小的计算方式,TabBarIndicatorSize.tab:跟每个tab等宽,TabBarIndicatorSize.label:跟文字等宽
this.labelColor,//选中label的颜色
this.labelStyle,//选中label的样式
this.labelPadding,每个label的padding
this.unselectedLabelColor,//未选中label的颜色
this.unselectedLabelStyle,//未选中label的样式
}) : assert(tabs != null),
assert(isScrollable != null),
assert(indicator != null || (indicatorWeight != null && indicatorWeight > 0.0)),
assert(indicator != null || (indicatorPadding != null)),
super(key: key);
  • TabBarView
  const TabBarView({
Key key,
@required this.children,//Tab页内容组件的数组集合
this.controller,//TabController对象
this.physics,
}) : assert(children != null), super(key: key);

总结一下使用吧:一般流程就是初始化tabs的List列表,先把选项卡的选项初始化出来,接下来就是DefaultTabController把TabBar和TabBarView关联起来,最后就是给TabBar和TabBarView设置各种属性来满足需求。

顶部导航TabBar、TabBarView、DefaultTabController的更多相关文章

  1. Flutter学习笔记(17)--顶部导航TabBar、TabBarView、DefaultTabController

    如需转载,请注明出处:Flutter学习笔记(17)--顶部导航TabBar.TabBarView.DefaultTabController 上一篇我们说了BottmNavigationBar底部导航 ...

  2. 天书笔记:HTML+CSS实现顶部导航栏

    此笔记纯属本人脑残笔记,阅读困难不理解属正常现象,初学者尽量不要阅读,否则轻则口吐白沫重则走火入魔,切记切记 先晒效果图: 效果要求类似于b站的顶部导航(..原谅我老是拿b站做例子:) ) 然后是代码 ...

  3. android开发(49) android 使用 CollapsingToolbarLayout ,可折叠的顶部导航栏

    概述 在很app上都见过 可折叠的顶部导航栏效果.google support v7  提供了 CollapsingToolbarLayout 可以实现这个效果.效果图如下:    实现步骤 1. 写 ...

  4. 更改SharePoint 2010 顶部导航为下拉菜单样式

      更改SharePoint 2010 顶部导航为下拉菜单样式 最后的效果图: 假如一个网站集顶级站点下面有子网站:sub site1,该子站点下面又有两个子站点:sub site1_1,sub si ...

  5. yii2顶部导航使用

    yii2中使用顶部导航的具体方法: 1.视图中调用两个类: use yii\bootstrap\Nav;use yii\bootstrap\NavBar; 2. <?php            ...

  6. jQuery 顶部导航尾随滚动,固定浮动在顶部

    jQuery 顶部导航尾随滚动.固定浮动在顶部 演示 XML/HTML Code <section> <article class="left"> < ...

  7. [置顶] xamarin Tablayout+Viewpager+Fragment顶部导航栏

    最近几天不忙,所以把项目中的顶部导航栏的实现归集一下.android中使用TabLayout+ViewPager+Fragment制作顶部导航非常常见,代码实现也比较简单.当然我这个导航栏是基于xam ...

  8. bootstrap顶部导航遮挡下面内容的解决办法

    使用bootstrap设置顶部导航,并将导航栏固定,代码如下: <nav class="navbar navbar-expand-lg navbar-light bg-light fi ...

  9. react native (2) 嵌入h5页面 设置顶部导航

    嵌入h5页面 1.新建好页面 2. import { WebView } from 'react-native'; 3.<WebView source={{ uri: '要引入的页面路径' }} ...

随机推荐

  1. 调用office Word Com 组件,提示权限不足处理

    最近一直在处理一个项目,项目主要功能与Office-Word 有关,主要涉及到文本内容编辑与样式设置等相关内容.因项目依赖office 相关dll,需要兼容多种Office 版本(office 200 ...

  2. Linux基础命令-查看基本硬件信息

    Linux基础命令-查看基本硬件信息 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.查看CPU信息 [root@node101.yinzhengjie.org.cn ~]# l ...

  3. GTID主从与传统主从复制

    目录 1.主从复制 2.靠什么同步 3.pos与GTID的什么区别 4.GTID的工作原理 5.GTID参数配置 5.1 在主数据库里创建一个同步账号授权给从数据库使用 5.2 配置主数据库 5.3配 ...

  4. mysql考生号后三位对出密号

    select mihao,substring(t1.kaohao, -3)  from t_zhaosheng_zhiyuan as t1 where substring(t1.kaohao, -3) ...

  5. Codeforces E. Alyona and a tree(二分树上差分)

    题目描述: Alyona and a tree time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  6. 学习Microsoft Visio(1)

    基础篇 一.认识Visio 1.Visio是什么 Visio最初属于Visio公司,该公司成立于1990年9月.1992年,公司更名为Shapeware.同年11月,它发布了他们公司的第一个产品:Vi ...

  7. Nginx+keepalived 高可用双机热备(主从模式)

    环境:centos7.6 最小化安装 主:10.11.1.32 从:10.11.1.33 VIP:10.11.1.130 修改主节点主机名: hostnamectl set-hostname web_ ...

  8. L1025

    1,对于搜索,我有一个不成熟的想法,这不就是,强化版的for循环吗? 2,反正是搜索,那就先找搜索状态, n,x,n是第几次分,x是分剩下的数. 3,这个我觉得自己努力努力可能可以做出来. 4,首先要 ...

  9. LeetCode 428. Serialize and Deserialize N-ary Tree

    原题链接在这里:https://leetcode.com/problems/serialize-and-deserialize-n-ary-tree/ 题目: Serialization is the ...

  10. 微信H5中禁止分享好友及分享到朋友圈的方法

    我们可以直接把以下代码加入到页面中,即可限制住各类分享. <script> function onBridgeReady() { WeixinJSBridge.call('hideOpti ...