DrawerStackController class

author: 郑再红 email: 1096877329@qq.com date: 2024-12-05 DrawerStackController - 抽屉路由栈控制器

使用 GlobalKey 管理抽屉状态,解决 context 依赖和时序问题

示例:

final scaffoldKey = GlobalKey<ScaffoldState>();
final controller = DrawerStackController(
  scaffoldKey: scaffoldKey,
  routerProxy: RouterProxy.getDrawerInstance(
    stackId: 'main-drawer',
    pageMap: {'/': HomePage()},
  ),
  config: DrawerConfig(autoOpen: true, autoClose: true),
);

Scaffold(
  key: scaffoldKey,
  endDrawer: DrawerNavigator(controller: controller),
  body: ElevatedButton(
    onPressed: () => controller.push(page: SettingsPage()),
  ),
)

Coordinates a drawer-specific RouterProxy with a ScaffoldState.

Constructors

DrawerStackController({required GlobalKey<ScaffoldState> scaffoldKey, required RouterProxy routerProxy, required DrawerConfig config})

Properties

config → DrawerConfig
抽屉配置 Drawer behavior settings.
final
hashCode → int
The hash code for this object.
no setterinherited
isDrawerOpen → bool
检查抽屉是否打开 Returns whether the configured drawer is currently open.
no setter
pages → List<MaterialPage<Object?>>
获取当前页面栈 Exposes the current drawer page stack.
no setter
routerProxy → RouterProxy
底层的 RouterProxy 实例,管理页面栈 The router instance that owns the drawer page stack.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
scaffoldKey → GlobalKey<ScaffoldState>
Scaffold 的 GlobalKey,用于访问 ScaffoldState The scaffold key used to access the host ScaffoldState.
final

Methods

build(BuildContext context) → Widget
Builds the drawer navigator widget tree.
closeDrawer() → void
手动关闭抽屉 Closes the drawer manually.
dispose({bool disposeRouter = false}) → void
清理资源
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openDrawer() → void
手动打开抽屉 Opens the drawer manually.
pop([Object? result]) → void
弹出当前页面 Pops the current page from the drawer stack.
push({required Widget page, String? name, Object? arguments, ResultCallback? onResult}) → Future<void>
推入新页面 Pushes a page onto the drawer stack.
pushNamed({required String name, Object? arguments, ResultCallback? onResult}) → Future<void>
根据名称推入新页面 Pushes a named page onto the drawer stack.
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited

Static Properties

debugLogging ↔ bool
是否输出调试日志。release 下默认关闭。
getter/setter pair