tabs

概述

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

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

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

TabBarView

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 const TabBar({
Key? key,
required this.tabs,//一系列标签控件
this.controller,//一系列标签控件
this.isScrollable = false,//是否可滚动,默认false
this.padding,
this.indicatorColor,//是否可滚动,默认false
this.automaticIndicatorColorAdjustment = true,
this.indicatorWeight = 2.0,//是否可滚动,默认false
this.indicatorPadding = EdgeInsets.zero,
this.indicator,//是否可滚动,默认false
this.indicatorSize,//指示器长短,tab:和tab一样长,label:和标签label 一样长
this.labelColor,//标签颜色
this.labelStyle,//标签颜色
this.labelPadding,//标签颜色
this.unselectedLabelColor,//标签颜色
this.unselectedLabelStyle,//标签颜色
this.dragStartBehavior = DragStartBehavior.start,
this.overlayColor,
this.mouseCursor,
this.enableFeedback,
this.onTap,
this.physics,
indicator, //自定义指示器,比如使用UnderlineTabIndicator
})

Read More

toggle_buttons

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

const ToggleButtons({
Key key,
@required this.children,
@required this.isSelected,
this.onPressed, // 点击状态
this.mouseCursor,
this.textStyle, // 文本样式
this.constraints, // 宽高最大最小限制
this.color, // 未选中颜色
this.selectedColor, // 选中颜色
this.disabledColor, // 不可选中颜色
this.fillColor, // 填充颜色
this.focusColor, // 有输入焦点时颜色
this.highlightColor, // 选中时高亮颜色
this.hoverColor, // 初始水波纹颜色
this.splashColor, // 选中时水波纹颜色
this.focusNodes, // 接受对应于每个切换按钮焦点列表
this.renderBorder = true, // 是否绘制边框
this.borderColor, // 未选中边框颜色
this.selectedBorderColor, // 选中边框颜色
this.disabledBorderColor, // 不可选中边框颜色
this.borderRadius, // 边框圆角弧度
this.borderWidth, // 边框宽度
})

async

FutureBuilder

1
2
3
4
5
6
7
8
9
10
11
FutureBuilder({
this.future, //通常是一个异步耗时任务
this.initialData,//初始数据
required this.builder,//Widget构造器,该builder会在Future执行的不同阶段被调用多次
})

final AsyncWidgetBuilder<T> builder;

//snapshot包含当前异步任务的状态信息及结果
typedef AsyncWidgetBuilder<T> = Widget Function(BuildContext context, AsyncSnapshot<T> snapshot);

实例

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40


Widget build(BuildContext context) {
return Center(
child: FutureBuilder<String>(
future: mockNetworkData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
// 请求已结束
if (snapshot.connectionState == ConnectionState.done) {
if (snapshot.hasError) {
// 请求失败,显示错误
return Text("Error: ${snapshot.error}");
} else {
// 请求成功,显示数据
return Text("Contents: ${snapshot.data}");
}
} else {
// 请求未结束,显示loading
return CircularProgressIndicator();
}
},
),
);
}

enum ConnectionState {
/// 当前没有异步任务,比如[FutureBuilder]的[future]为null时
none,

/// 异步任务处于等待状态
waiting,

/// Stream处于激活状态(流上已经有数据传递了),对于FutureBuilder没有该状态。
active,

/// 异步任务已经终止.
done,
}


Read More