StaticRouteFactory class

静态路由构建器

此路由构建器为StaticRoute的常用简单实现

所有静态路由页面都必须提供此静态实例 用于在MaterialApp.onGenerateRoute中注册, StaticRouteFactory实例应当使用同一名称route。 页面导航时使用名称导航方法。

典型用法


class ExamplePage extends StatelessWidget {

  ExamplePage(this.id, this.code);

  final String id;

  final int code;

  /// 本页面路由器
  static final route = StaticRouteFactory(
    name: 'ExamplePage',
    builder: (BuildContext context, Object? arguments) {
      final args = arguments as List;

      return ExamplePage(args[0], args[1]);
    },
  );

  ...
}

final routeTable = <StaticRoute>[
 ExamplePage.route,
 ...
];

MaterialApp(
 onGenerateRoute: routeTable.generateRoute,
);

Navigator.pushNamed(context, ExamplePage.route.name, arguments: ['test', 123]);

  • maintainState, Whether the route should remain in memory when it is inactive.

If this is true, then the route is maintained, so that any futures it is holding from the next route will properly resolve when the next route pops. If this is not necessary, this can be set to false to allow the framework to entirely discard the route's widget hierarchy when it is not visible.

Setting maintainState to false does not guarantee that the route will be discarded. For instance, it will not be descarded if it is still visible because the next above it is not opaque (e.g. it is a popup dialog).

  • fullscreenDialog, Whether this page route is a full-screen dialog.

In Material and Cupertino, being fullscreen has the effects of making the app bars have a close button instead of a back button. On iOS, dialogs transitions animate differently and are also not closeable with the back swipe gesture.

  • allowSnapshotting, Whether the route transition will prefer to animate a snapshot of the entering/exiting routes.

When this value is true, certain route transitions (such as the Android zoom page transition) will snapshot the entering and exiting routes. These snapshots are then animated in place of the underlying widgets to improve performance of the transition.

Generally this means that animations that occur on the entering/exiting route while the route animation plays may appear frozen - unless they are a hero animation or something that is drawn in a separate overlay.

  • barrierDismissible, Whether you can dismiss this route by tapping the modal barrier.

The modal barrier is the scrim that is rendered behind each route, which generally prevents the user from interacting with the route below the current route, and normally partially obscures such routes.

For example, when a dialog is on the screen, the page below the dialog is usually darkened by the modal barrier.

If barrierDismissible is true, then tapping this barrier, pressing the escape key on the keyboard, or calling route popping functions such as Navigator.pop will cause the current route to be popped with null as the value.

If barrierDismissible is false, then tapping the barrier has no effect.

If this getter would ever start returning a different value, either changedInternalState or changedExternalState should be invoked so that the change can take effect.

It is safe to use navigator.context to look up inherited widgets here, because the Navigator calls changedExternalState whenever its dependencies change, and changedExternalState causes the modal barrier to rebuild.

See also:

  • Navigator.pop, which is used to dismiss the route.
  • barrierColor, which controls the color of the scrim for this route.
  • ModalBarrier, the widget that implements this feature.
Inheritance

Constructors

StaticRouteFactory({required String name, required StaticRouteWidgetBuilder builder, bool maintainState = true, bool fullscreenDialog = false, bool allowSnapshotting = true, bool barrierDismissible = false, OnStaticRouteExit? onExit})

Properties

builder RouteFactory
路由构建器
finalinherited
hashCode int
The hash code for this object.
no setterinherited
name String
页面名称
finalinherited
onExit OnStaticRouteExit?
静态路由页面退出回调
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

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