顶部导航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: '要引入的页面路径' }} ...
随机推荐
- 《linux就该这么学》课堂笔记02 虚拟机安装使用
这节学习了虚拟机安装RHEL系统,了解了shell.以及命令的格式
- js的insertRow和insertCell用法
js的insertRow(-1)和insertCell(-1) 增加最后一行和增加最后一列 js的insertRow(5)和insertCell(5) 第5行后增加一行和增加第5列后增加一列
- java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver
java.lang.ClassNotFoundException: com.mysql.cj.jdbc.Driver at java.net.URLClassLoader.findClass(URLC ...
- Visual Studio Code 写Python代码
之前用nodepad++,sublime text3,ultraedit,最近上手微软的vsc感觉上手还行,如果没有pycharm照样可以使用它 https://code.visualstudio.c ...
- 解决PHP处理图片时内存占用过高问题
用过GD库的同学可能都知道,使用imagecreatetruecolor()函数创建一个真彩色的画布是第一步.但是,如果画布的宽高超过平常的宽高,会带来极大的内存消耗.比如,一个9600×4800的画 ...
- siblings,next,prev
同胞拥有相同的父元素. 通过 jQuery,您能够在 DOM 树中遍历元素的同胞元素. 在 DOM 树中水平遍历 siblings() next() nextAll() nextUntil() pre ...
- Python基础初始之二
1.格式化的输出 当你遇到这样的需要:字符串中想让某些位置变成动态可传入的,首先考虑用格式化输出 1.格式化输出:% 2. 格式化输出:format 3. 格式化输出:f 2.运算符 3.编码 待续
- django-缓存django-redis
https://django-redis-chs.readthedocs.io/zh_CN/latest/ 安装 django-redis 最简单的方法就是用 pip : pip install dj ...
- [Codeforces Educational Round 71]Div. 2
总结 手速场...像我这种没手速的就直接炸了... 辣鸡 E 题交互,少打了个 ? 调了半个小时... 到最后没时间 G 题题都没看就结束了...结果早上起来被告知是阿狸的打字机...看了看题一毛一样 ...
- 开源项目 02 HttpLib
using JumpKick.HttpLib; using Newtonsoft.Json; using System; using System.Collections.Generic; using ...