BaseTabBar class
自定义 TabBar 组件
特性:
- 可滚动:当 Tab 总宽度超过可用空间时,支持横向滚动
- 从左开始排列:Tab 从左侧开始排列,不居中
- Tab 宽度自适应:每个 Tab 的宽度根据标题文本自动调整,不均分可用空间
- 右侧留白:如果右边还有空间,则留白,不填充
- Indicator 对齐:支持左对齐、居中对齐、右对齐三种方式
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- BaseTabBar
- Implemented types
Constructors
-
BaseTabBar({Key? key, required TabController controller, required List<
String> tabs, bool smoothIndicator = true, ValueChanged<int> ? onChange, Color? labelColor, Color? unselectedLabelColor, TextStyle? labelStyle, TextStyle? unselectedLabelStyle, EdgeInsetsGeometry? tabPadding, double? tabSpacing, Color? indicatorColor, double? indicatorHeight, double? indicatorWidth, EdgeInsetsGeometry? indicatorPadding, IndicatorAlignment indicatorAlignment = IndicatorAlignment.center, Color? backgroundColor, double? height, ScrollController? scrollController})
Properties
- backgroundColor → Color?
-
背景颜色
final
- controller → TabController
-
TabController,用于控制 Tab 的选中状态
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- height → double?
-
TabBar 的高度
final
- indicatorAlignment → IndicatorAlignment
-
指示器对齐方式
final
- indicatorColor → Color?
-
指示器颜色(下划线颜色)
final
- indicatorHeight → double?
-
指示器高度
final
- indicatorPadding → EdgeInsetsGeometry?
-
指示器padding
final
- indicatorWidth → double?
-
指示器宽度(如果为 null,则自适应 Tab 宽度)
final
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- labelColor → Color?
-
选中的 Tab 文字颜色
final
- labelStyle → TextStyle?
-
选中的 Tab 文字样式
final
-
onChange
→ ValueChanged<
int> ? -
Tab 切换时的回调,参数为当前选中 tab 的索引
final
- preferredSize → Size
-
The size this widget would prefer if it were otherwise unconstrained.
no setteroverride
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- scrollController → ScrollController?
-
可选外部滚动控制器,若为 null 则内部创建并管理
final
- smoothIndicator → bool
-
是否启用平滑指示器(基于 TabController.animation 插值)
在低端设备上可以将此项设为 false,以关闭精确监听并使用原始 index 驱动的指示器更新。
final
- tabPadding → EdgeInsetsGeometry?
-
Tab 的内边距
final
-
tabs
→ List<
String> -
Tab 标题列表
final
- tabSpacing → double?
-
Tab 之间的间距
final
- unselectedLabelColor → Color?
-
未选中的 Tab 文字颜色
final
- unselectedLabelStyle → TextStyle?
-
未选中的 Tab 文字样式
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< BaseTabBar> -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of DiagnosticsNode objects describing this node's
children.
inherited
-
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited