EasySplitRouterDelegate class

原生 router 模式(MaterialApp.router,无 go_router)的 RouterDelegate

行为与 onGenerateRoute 方案完全一致,页面代码零改动:

  • Navigator.pushNamed(context, '/detail') → 宽屏右栏 / 窄屏全屏
  • Navigator.pop(context) / 系统返回 → 正常返回
  • pushReplacementNamed / pushNamedAndRemoveUntil 等与原生一致
  • 页面参数仍用 ModalRoute.of(context)!.settings.arguments 获取
MaterialApp.router(
  routerConfig: easySplitNativeRouterConfig(
    home: RootPage(),                                   // 启动首路由 '/'
    pageBuilders: {                                     // 与 routeAdapter 同一张表
      '/detail': (_) => DetailPage(),
      '/home': (_) => EasySplitScope(child: HomePage()), // 左栏自己包 Scope
    },
  ),
)

注意:

  1. home 就是 '/' 路由本身,不会被自动包 EasySplitScope —— 谁是左栏由你在对应路由的 builder 里决定(与 onGenerateRoute 方案一致)。
  2. routerConfig 请在 build 之外只创建一次(字段 / late final), 否则每次重建都会生成新的 Navigator,路由栈会被重置。

内置增强(页面代码依旧零改动):

Inheritance
Mixed-in types

Constructors

EasySplitRouterDelegate({required Widget home, required Map<String, WidgetBuilder> pageBuilders, List<NavigatorObserver> observers = const <NavigatorObserver>[], RouteFactory? onUnknownRoute})

Properties

currentConfiguration → String?
Called by the Router when it detects a route information may have changed as a result of rebuild.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
hasListeners → bool
Whether any listeners are currently registered.
no setterinherited
home → Widget
启动首路由 '/' 的内容(原 MaterialApp.home)
final
The key used for retrieving the current navigator.
no setteroverride
observers → List<NavigatorObserver>
追加给内部 Navigator 的观察者(与原生 navigatorObservers 等价)
final
onUnknownRoute → RouteFactory?
未注册路由的兜底(命中不到 pageBuilders 时交给它)
final
pageBuilders → Map<String, WidgetBuilder>
页面构建表:name → 页面构建器(与原 onGenerateRoute 的 routes 表相同)
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

addListener(VoidCallback listener) → void
Register a closure to be called when the object changes.
inherited
build(BuildContext context) → Widget
Called by the Router to obtain the widget tree that represents the current state.
override
dispose() → void
Discards any resources used by the object.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
notifyListeners() → void
Call all the registered listeners.
inherited
pop<T extends Object?>([T? result]) → Future<bool>
等价于 Navigator.pop
popRoute() → Future<bool>
Called by the Router when the Router.backButtonDispatcher reports that the operating system is requesting that the current route be popped.
inherited
push(String name, {Object? arguments}) → void
等价于 Navigator.pushNamed:方便持有 delegate 的代码直接跳转
removeListener(VoidCallback listener) → void
Remove a previously registered closure from the list of closures that are notified when the object changes.
inherited
setInitialRoutePath(String configuration) → Future<void>
Called by the Router at startup with the structure that the RouteInformationParser obtained from parsing the initial route.
inherited
setNewRoutePath(String configuration) → Future<void>
Called by the Router when the Router.routeInformationProvider reports that a new route has been pushed to the application by the operating system.
override
setRestoredRoutePath(String configuration) → Future<void>
Called by the Router during state restoration.
inherited
toString() → String
A string representation of this object.
inherited

Operators

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