restorablePush<T extends Object?> static method
- BuildContextcontext,
- RestorableRouteBuilder<
T> routeBuilder, { - Object?arguments,
Push a new route onto the navigator that most tightly encloses thegiven context.
UnlikeRoutes pushed viapush,Routes pushed with this method arerestored during state restoration according to the rules outlined in the"State Restoration" section ofNavigator.
The new route and the previous route (if any) are notified (seeRoute.didPush andRoute.didChangeNext). If theNavigator has anyNavigator.observers, they will be notified as well (seeNavigatorObserver.didPush).
Ongoing gestures within the current route are canceled when a new route ispushed.
TheT type argument is the type of the return value of the route.
The method takes aRestorableRouteBuilder as argument, which must be astatic function annotated with@pragma('vm:entry-point'). It mustinstantiate and return a newRoute object that will be added to thenavigator. The providedarguments object is passed to therouteBuilder. The navigator calls the staticrouteBuilder functionagain during state restoration to re-create the route object.
Any object that is serializable via theStandardMessageCodec can bepassed asarguments. Often, a Map is used to pass key-value pairs.
The method returns an opaque ID for the pushed route that can be used bytheRestorableRouteFuture to gain access to the actualRoute objectadded to the navigator and its return value. You can ignore the returnvalue of this method, if you do not care about the route object or theroute's return value.
To create a local project with this code sample, run:
flutter create --sample=widgets.Navigator.restorablePush.1 mysample
Implementation
@optionalTypeArgsstatic String restorablePush<T extends Object?>( BuildContext context, RestorableRouteBuilder<T> routeBuilder, { Object? arguments,}) { return Navigator.of(context).restorablePush(routeBuilder, arguments: arguments);}