MyTabView class
macOS 风格的 Tab 视图组件
将 MySegmentedControl(Tab 栏)和内容区域组合在一起, 提供完整的 Tab 切换体验。支持顶部/底部两种 Tab 位置。
布局原理:采用 Stack 布局,Tab 栏通过 Positioned 骑在内容区边框的 中线上(与 macOS 原生风格一致)。padding 参数控制内容区向内缩进的距离, 约为 Tab 栏高度的一半时,Tab 栏恰好居中在边框线上。
注意:此组件需要有界高度约束(bounded height), 请将其放在 SizedBox、Expanded 或其他提供高度约束的容器中。
示例:
SizedBox(
height: 300.h,
child: MyTabView(
tabs: [MyTab(label: '棋谱'), MyTab(label: '日志')],
children: [ChessRecordView(), LogView()],
position: MyTabPosition.bottom,
),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- MyTabView
- Available extensions
Constructors
-
MyTabView({Key? key, required List<
MyTab> tabs, required List<Widget> children, MyTabController? controller, MyTabPosition position = MyTabPosition.top, MyTabBarFit tabBarFit = MyTabBarFit.compact, EdgeInsetsGeometry? padding, Color? contentBackgroundColor, Color? contentBorderColor, double? contentBorderWidth, BorderRadius? contentBorderRadius, Color? tabBarBackgroundColor, BorderRadius? tabBarBorderRadius, EdgeInsetsGeometry? tabBarPadding, List<BoxShadow> ? tabBarBoxShadow, Color? dividerColor, double? dividerWidth, double? dividerIndent, Duration? slideDuration, Curve? slideCurve, AnimatedSwitcherTransitionBuilder? transitionBuilder, Duration? transitionDuration}) -
const
Properties
-
children
→ List<
Widget> -
每个 Tab 对应的内容 Widget,数量必须与 tabs 一致
final
- contentBackgroundColor → Color?
-
内容区背景色(默认:亮色 #E6E9EA,暗色 #2B2E33)
final
- contentBorderColor → Color?
-
内容区边框色(默认:亮色 #E1E2E4,暗色 #3E4045)
final
- contentBorderRadius → BorderRadius?
-
内容区圆角
final
- contentBorderWidth → double?
-
内容区边框宽度
final
- controller → MyTabController?
-
Tab 控制器(可选,不传则内部自动创建并管理)
final
- dividerColor → Color?
-
Tab 栏分隔线颜色
final
- dividerIndent → double?
-
Tab 栏分隔线缩进
final
- dividerWidth → double?
-
Tab 栏分隔线宽度
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- marginZero → Widget
-
Available on Widget, provided by the WidgetMarginX extension
no setter - padding → EdgeInsetsGeometry?
-
内容区外层 padding
final
- paddingZero → Widget
-
Available on Widget, provided by the WidgetPaddingX extension
no setter - position → MyTabPosition
-
Tab 栏位置,默认顶部
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- slideCurve → Curve?
-
选中态滑块动画曲线(默认 Curves.easeInOut)
final
- slideDuration → Duration?
-
选中态滑块动画时长(默认 200ms)
final
- sliverBox → Widget
-
Available on Widget, provided by the WidgetSliverBoxX extension
no setter - tabBarBackgroundColor → Color?
-
Tab 栏背景色
final
- tabBarBorderRadius → BorderRadius?
-
Tab 栏圆角
final
-
tabBarBoxShadow
→ List<
BoxShadow> ? -
Tab 栏阴影
final
- tabBarFit → MyTabBarFit
-
Tab 栏水平布局模式
final
- tabBarPadding → EdgeInsetsGeometry?
-
Tab 栏内部 padding
final
-
tabs
→ List<
MyTab> -
Tab 数据列表
final
- transitionBuilder → AnimatedSwitcherTransitionBuilder?
-
页面切换动画构建器(默认 null 表示无动画,使用 IndexedStack)
final
- transitionDuration → Duration?
-
切换动画时长(默认 300ms,仅在 transitionBuilder 不为 null 时生效)
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< MyTabView> -
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
-
marginAll(
double margin) → Widget -
Available on Widget, provided by the WidgetMarginX extension
-
marginOnly(
{double left = 0.0, double top = 0.0, double right = 0.0, double bottom = 0.0}) → Widget -
Available on Widget, provided by the WidgetMarginX extension
-
marginSymmetric(
{double horizontal = 0.0, double vertical = 0.0}) → Widget -
Available on Widget, provided by the WidgetMarginX extension
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
paddingAll(
double padding) → Widget -
Available on Widget, provided by the WidgetPaddingX extension
-
paddingOnly(
{double left = 0.0, double top = 0.0, double right = 0.0, double bottom = 0.0}) → Widget -
Available on Widget, provided by the WidgetPaddingX extension
-
paddingSymmetric(
{double horizontal = 0.0, double vertical = 0.0}) → Widget -
Available on Widget, provided by the WidgetPaddingX extension
-
setFocus(
{String? focusKey, VoidCallback? onPressed, bool opacity = false, Color focusedBorderColor = Colors.grey, double borderWidth = 1.5, Duration animationDuration = const Duration(milliseconds: 350), double opacityBeginScale = 0.65}) → Widget -
Available on Widget, provided by the XlyFocusableExtension extension
-
showRightMenu(
{required BuildContext context, MyMenuPopStyle animationStyle = MyMenuPopStyle.reveal, MyMenuStyle? style}) → Widget -
Available on Widget, provided by the RightClickMenuExtension extension
-
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