顶部导航TabBar、TabBarView、DefaultTabController
原文地址:https://www.cnblogs.com/upwgh/p/11369537.html
TabBar:Tab页的选项组件,默认为水平排列。
TabBarView:Tab页的内容容器,Tab页内容一般处理为随选项卡的改变而改变。
TabController:TabBar和TabBarView的控制器,它是关联这两个组件的桥梁。
属性名 | 类型 | 说明 |
isScrollable | bool | 是否可以水平移动 |
tabs | List<Widget> | Tab选项列表 |
属性名 | 类型 | 说明 |
icon | Widget | Tab图标 |
text | String | Tab文本 |
属性名 | 类型 | 说明 |
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的更多相关文章
- Flutter学习笔记(17)--顶部导航TabBar、TabBarView、DefaultTabController
如需转载,请注明出处:Flutter学习笔记(17)--顶部导航TabBar.TabBarView.DefaultTabController 上一篇我们说了BottmNavigationBar底部导航 ...
- 天书笔记:HTML+CSS实现顶部导航栏
此笔记纯属本人脑残笔记,阅读困难不理解属正常现象,初学者尽量不要阅读,否则轻则口吐白沫重则走火入魔,切记切记 先晒效果图: 效果要求类似于b站的顶部导航(..原谅我老是拿b站做例子:) ) 然后是代码 ...
- android开发(49) android 使用 CollapsingToolbarLayout ,可折叠的顶部导航栏
概述 在很app上都见过 可折叠的顶部导航栏效果.google support v7 提供了 CollapsingToolbarLayout 可以实现这个效果.效果图如下: 实现步骤 1. 写 ...
- 更改SharePoint 2010 顶部导航为下拉菜单样式
更改SharePoint 2010 顶部导航为下拉菜单样式 最后的效果图: 假如一个网站集顶级站点下面有子网站:sub site1,该子站点下面又有两个子站点:sub site1_1,sub si ...
- yii2顶部导航使用
yii2中使用顶部导航的具体方法: 1.视图中调用两个类: use yii\bootstrap\Nav;use yii\bootstrap\NavBar; 2. <?php ...
- jQuery 顶部导航尾随滚动,固定浮动在顶部
jQuery 顶部导航尾随滚动.固定浮动在顶部 演示 XML/HTML Code <section> <article class="left"> < ...
- [置顶]
xamarin Tablayout+Viewpager+Fragment顶部导航栏
最近几天不忙,所以把项目中的顶部导航栏的实现归集一下.android中使用TabLayout+ViewPager+Fragment制作顶部导航非常常见,代码实现也比较简单.当然我这个导航栏是基于xam ...
- bootstrap顶部导航遮挡下面内容的解决办法
使用bootstrap设置顶部导航,并将导航栏固定,代码如下: <nav class="navbar navbar-expand-lg navbar-light bg-light fi ...
- react native (2) 嵌入h5页面 设置顶部导航
嵌入h5页面 1.新建好页面 2. import { WebView } from 'react-native'; 3.<WebView source={{ uri: '要引入的页面路径' }} ...
随机推荐
- 前端cdn库推荐
后端编程人员,有时作功能调试时会用到jquery.layer等的前端库文件,用得较多的我们可以下载下来放到自己的电脑上,有些偶尔使用一次的类库插件就没必要全都下载下来,毕竟不用的类库多了,自己找到它都 ...
- 云计算与大数据实验:Hbase shell终端操作之数据操作一
[实验目的] 1)学会向表中添加记录 2)学会添加记录时动态添加列 3)学会查看一条记录 4)学会查看表中的记录总数 5)学会删除记录 [实验原理] Hbase shell作为Hbase数据的客户端, ...
- 树莓派安装系统+ssh登录
一.准备工作: (1)树莓派3b (2)官网下载系统 (3)SD卡 (4)网线 (5)SDFormatter.exe (6)win32diskimager.exe (7)putty (7)笔记本 二. ...
- git track remot
echo "# test" >> README.md git init git add README.md git commit -m "first comm ...
- selenium与webdriver驱动与firefox、 chrome匹配版本
一.Chrome python3 selenium3.11.0(直接pip安装即可) chromedriver_win32:2.38 Chrome版本: 65.0.3325.146(正式版本)(32 ...
- STM32 IAP程序 源码 和测试代码 有详细的中文注释
http://bbs.21ic.com/forum.php?mod=viewthread&tid=588265&reltid=624002&pre_pos=2&ext= ...
- Centos7安装Hadoop2.7
准备 1.三台Centos7的机器: hostname IP地址 部署规划 node1 172.20.0.4 NameNode.DataNode node2 172.20.0.5 DataNode n ...
- Idea中,项目文件右键菜单没有svn选项处理办法
问题描述 IntelliJ IDEA打开带SVN信息的项目,在项目文件上点击右键,菜单中没有Subversion的功能项,如下图: 解决办法 点击菜单:VCS -> Enabled Versio ...
- tornado处理跨域问题
报错信息一: Access to XMLHttpRequest at 'http://localhost:4445/api/v/getmsg' from origin 'http://localhos ...
- 关于H5判定区域里面滑动到底部,加载更多的总结
1.如何判定H5中滑动到底部,然后加载更多的功能实现. 思路:我们需要设定一个固定高度的盒子,然后我们利用scroll来监听滚动,当scrollTop(滚动的距离) + clientHeight(页面 ...