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()),
  ),
)

Constructors

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

Properties

config DrawerConfig
抽屉配置
final
hashCode int
The hash code for this object.
no setterinherited
isDrawerOpen bool
检查抽屉是否打开
no setter
pages List<MaterialPage>
获取当前页面栈
no setter
routerProxy RouterProxy
底层的 RouterProxy 实例,管理页面栈
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
scaffoldKey GlobalKey<ScaffoldState>
Scaffold 的 GlobalKey,用于访问 ScaffoldState
final

Methods

build(BuildContext context) Widget
构建 Navigator Widget
closeDrawer() → void
手动关闭抽屉
dispose() → void
清理资源
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
openDrawer() → void
手动打开抽屉
pop<T>([T? result]) → void
弹出当前页面
push({required Widget page, String? name, Object? arguments, ResultCallBack? onResult}) Future<void>
推入新页面
pushNamed({required String name, Object? arguments, ResultCallBack? onResult}) Future<void>
根据名称推入新页面
toString() String
A string representation of this object.
inherited

Operators

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