MyScaffold class

自适应根脚手架(M3 五层级)

根据屏幕宽度自动切换 5 种显示模式:

  • Compact (< compactBreakpoint) :抽屉式导航或底部导航栏
  • Medium (compact ~ medium) :仅图标侧边栏(72dp),hover 显示 Tooltip
  • Expanded (medium ~ expanded) :图标+文字侧边栏(256dp)
  • Large (expanded ~ large) :完整导航抽屉(304dp),含分组标题、副标题、顶部 Header
  • XLarge (≥ largeBreakpoint) :宽导航抽屉(360dp),trailing 内嵌、间距更宽松

使用方式类似传统 Flutter Scaffold,但增加了自适应导航功能:

MyScaffold(
  appBar: AppBar(title: Text('My App')),
  drawer: [
    MyAdaptiveNavigationItem(
      icon: Icon(Icons.home),
      label: '首页',
      subtitle: '数据概览',  // 仅 Large+ 显示
      group: '主要功能',     // 仅 Large+ 显示分组标题
      onTap: () => controller.switchToPage(0),
    ),
  ],
  navigationHeader: MyHeaderWidget(), // 仅 Large+ 显示
  body: Obx(() => pages[controller.currentIndex]),
)
Inheritance
Available extensions

Constructors

MyScaffold({Key? key, List<MyAdaptiveNavigationItem>? drawer, @Deprecated('使用drawer参数代替') List<MyAdaptiveNavigationItem>? items, @Deprecated('不再需要pages参数') List<Widget>? pages, Widget? body, Widget? trailing, Widget? navigationHeader, bool useBottomNavigationOnSmall = false, PreferredSizeWidget? appBar, Widget? floatingActionButton, double drawerWidthRatio = 0.88, double compactBreakpoint = 600.0, double mediumBreakpoint = 840.0, double expandedBreakpoint = 1200.0, double largeBreakpoint = 1600.0, @Deprecated('请使用 compactBreakpoint 代替') double? smallBreakpoint, int initialSelectedIndex = 0, bool alwaysShowScrollbar = false, bool autoScrollToSelected = true})
const

Properties

alwaysShowScrollbar bool
是否始终显示侧边栏滚动条 默认为false,只在需要时显示
final
appBar PreferredSizeWidget?
应用栏(可选)
final
autoScrollToSelected bool
是否自动滚动到选中的导航项 默认为true,当路由变化时自动滚动让选中项可见
final
body Widget?
主体内容 类似传统Scaffold的body参数
final
compactBreakpoint double
Compact / Medium 分界宽度(默认 600dp) 宽度 < 此值时使用抽屉或底部导航栏
final
drawer List<MyAdaptiveNavigationItem>?
导航项列表(可选) 当提供时,会根据屏幕尺寸显示为抽屉、侧边栏或底部导航栏
final
drawerWidthRatio double
抽屉宽度比例(相对于屏幕宽度)
final
expandedBreakpoint double
Expanded / Large 分界宽度(默认 1200dp) 宽度 ≥ 此值时显示完整导航抽屉(含分组、副标题、Header)
final
floatingActionButton Widget?
浮动操作按钮(可选)
final
hashCode int
The hash code for this object.
no setterinherited
initialSelectedIndex int
初始选中的导航项索引
final
items List<MyAdaptiveNavigationItem>?
导航项列表(已废弃,请使用drawer参数)
final
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
largeBreakpoint double
Large / XLarge 分界宽度(默认 1600dp) 宽度 ≥ 此值时显示宽导航抽屉,trailing 内嵌
final
marginZero Widget

Available on Widget, provided by the WidgetMarginX extension

no setter
mediumBreakpoint double
Medium / Expanded 分界宽度(默认 840dp) 宽度 ≥ 此值时显示图标+文字侧边栏
final
导航侧边栏顶部区域(可选) 仅在 Large (1200dp+) 层级及 Compact 抽屉中显示 适合放置应用 Logo、用户头像等
final
paddingZero Widget

Available on Widget, provided by the WidgetPaddingX extension

no setter
pages List<Widget>?
页面列表(已废弃)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
sliverBox Widget

Available on Widget, provided by the WidgetSliverBoxX extension

no setter
smallBreakpoint double?
小屏幕断点宽度(已废弃,请使用 compactBreakpoint)
final
trailing Widget?
侧边栏底部额外内容(可选)
final
useBottomNavigationOnSmall bool
是否在小屏幕使用底部导航栏而不是抽屉
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<MyScaffold>
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, required List<MyMenuElement> menuElements, MyMenuPopStyle animationStyle = MyMenuPopStyle.scale, 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