顶部导航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
![](https://common.cnblogs.com/images/copycode.gif)
const DefaultTabController({
Key key,
@required this.length,
this.initialIndex = 0,
@required this.child,
}) : assert(initialIndex != null),
super(key: key);
![](https://common.cnblogs.com/images/copycode.gif)
- TabBar
![](https://common.cnblogs.com/images/copycode.gif)
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);
![](https://common.cnblogs.com/images/copycode.gif)
- 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: '要引入的页面路径' }} ...
随机推荐
- 02-CSS常用样式
本篇主要介绍css的常用样式,以及网页布局相关知识.绝对定位和相对定位,盒子模型.css权重.以及css选择器: 绪论:CSS基本介绍 为了让网页元素的样式更加丰富,也为了让网页的内容和样式能拆分开, ...
- Codeforces C. Maximum Value(枚举二分)
题目描述: Maximum Value time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces I. Barcelonian Distance(暴力)
题目描述: In this problem we consider a very simplified model of Barcelona city. Barcelona can be repres ...
- Calendar.getInstance()获取指定时间点(定时)
public class Test1 { public static void main(String[]args){ System.out.println("时间为:\n"+ge ...
- Java.io.tmpdir介绍
System.getproperty(“java.io.tmpdir”)是获取操作系统缓存的临时目录,不同操作系统的缓存临时目录不一样, 在Windows的缓存目录为:C:\Users\登录用户~1\ ...
- NOIP2017 PJ 跳房子 —— 单调队列优化DP
题目描述 跳房子,也叫跳飞机,是一种世界性的儿童游戏,也是中国民间传统的体育游戏之一.跳房子的游戏规则如下: 在地面上确定一个起点,然后在起点右侧画n个格子,这些格子都在同一条直线上.每个格子内有一个 ...
- synchronize——对象锁和类锁
最近在研究Java 多线程的只是,经常能看到synchronize关键字,以前只是一眼带过,没有细究,今天趁这个机会,整理下 synchronize作为多线程关键字,是一种同步锁,它可以修饰以下几种对 ...
- git添加doc文件维护
原文地址:https://www.cnblogs.com/yezuhui/p/6853271.html 说明: git 一般只能对纯文本文件进行版本控制,但是如果有其他中间转化软件的协助,就可以对任意 ...
- Dynamics 365 On-premises和Online 的不同
1.新建账号的不同:on-premises(下文简称op)是和ad绑定的,所以必须先在ad中新建账号后才能在CRM中新建.而online是和Office365(下文简称O365)绑定的,所以需在O36 ...
- 关于AndroidStudio的apk打包遇到的问题记录
12月份末尾,想来个总结,主要是得记一些重要的. 首先就得是AndroidStudi内的apk打包,就是弄当前项目app的安装包出来. 下面就说下具体步骤和注意问题. 首先 : 看到AndroidSt ...