pub struct Navigator {Show 16 fields
pub key: Option<KeyRef>,
pub pages: Vec<PageRef>,
pub on_pop_page: Option<PopPageCallback>,
pub on_did_remove_page: Option<DidRemovePageCallback>,
pub transition_delegate: TransitionDelegateRef,
pub initial_route: Option<String>,
pub on_generate_route: Option<RouteFactory>,
pub on_unknown_route: Option<RouteFactory>,
pub observers: Vec<NavigatorObserverRef>,
pub restoration_scope_id: Option<String>,
pub route_traversal_edge_behavior: TraversalEdgeBehavior,
pub route_directional_traversal_edge_behavior: TraversalEdgeBehavior,
pub on_generate_initial_routes: RouteListFactory,
pub reports_route_update_to_engine: bool,
pub clip_behavior: Clip,
pub request_focus: bool,
}Expand description
A widget that manages a set of child widgets with a stack discipline.
Many apps have a navigator near the top of their widget hierarchy in order to display their
logical history using an Overlay with the most recently visited pages visually on top of
the older pages. Using this pattern lets the navigator visually transition from one page to
another by moving the widgets around in the overlay. Similarly, the navigator can be used to
show a dialog by positioning the dialog widget above the current page.
§Using the Pages API
The Navigator will convert its pages into a stack of Routes if it is
provided. A change in pages will trigger an update to the stack of routes. To use this API,
implement Page and define a list of pages for pages. An
on_did_remove_page callback is also required to properly clean
up the input pages in case of a pop.
By default, the Navigator will use DefaultTransitionDelegate to decide how routes
transition in or out of the screen.
§Using the Navigator API
The navigator manages a stack of Route objects and provides two ways for managing the
stack, the declarative API pages or the imperative API
push and pop.
Fields§
§key: Option<KeyRef>See Widget::key.
pages: Vec<PageRef>The list of pages with which to populate the history.
Pages are turned into routes using Page::create_route in a manner analogous to how
on_generate_route turns RouteSettings into Routes.
When this list is updated, the new list is compared to the previous list and the set of routes is updated accordingly.
on_pop_page: Option<PopPageCallback>Called when pop is invoked but the current Route corresponds to a
Page found in the pages list.
Dart’s deprecated onPopPage; on_did_remove_page is its
replacement.
on_did_remove_page: Option<DidRemovePageCallback>Called when a Route created from a Page in pages is removed.
This must update the pages list the next time it is passed into pages so
that it no longer includes the input page.
transition_delegate: TransitionDelegateRefThe delegate used for deciding how routes transition in or off the screen during the
pages updates.
initial_route: Option<String>The name of the first route to show.
Defaults to Navigator::DEFAULT_ROUTE_NAME.
If this string contains any / characters, then the string is split on those characters
and substrings from the start of the string up to each such character are, in turn, used
as routes to push.
on_generate_route: Option<RouteFactory>Called to generate a route for a given RouteSettings.
on_unknown_route: Option<RouteFactory>Called when on_generate_route fails to generate a route.
This callback is typically used for error handling. It receives the RouteSettings and
must return a non-None Route.
observers: Vec<NavigatorObserverRef>A list of observers for this navigator.
restoration_scope_id: Option<String>Restoration ID to save and restore the state of the navigator, including its history.
If a restoration ID is provided, the navigator will persist its internal state (including
the route history) to the surrounding RestorationScope and restore it during state
restoration.
route_traversal_edge_behavior: TraversalEdgeBehaviorControls the transfer of focus beyond the first and the last items of a focus scope that defines focus traversal of widgets within a route.
route_directional_traversal_edge_behavior: TraversalEdgeBehaviorControls the transfer of focus beyond the first and the last items of a focus scope that defines focus traversal of widgets within a route, in a directional traversal.
on_generate_initial_routes: RouteListFactoryCalled when the widget is created to generate the initial list of Route objects if
initial_route is not None.
Defaults to Navigator::default_generate_initial_routes.
reports_route_update_to_engine: boolWhether this navigator should report route update message back to the engine when the top-most route changes.
clip_behavior: ClipThe content will be clipped (or not) according to this option.
Defaults to Clip::HardEdge.
request_focus: boolWhether or not the navigator and it’s new topmost route should request focus when the new route is pushed onto the navigator.
Defaults to true.
Implementations§
Sourcepub const DEFAULT_ROUTE_NAME: &'static str = "/"
pub const DEFAULT_ROUTE_NAME: &'static str = "/"
The default name for the initial_route.
See also:
dart:ui.PlatformDispatcher.defaultRouteName, which reflects the route that the application was started with.
Sourcepub fn new() -> Navigator
pub fn new() -> Navigator
Creates a widget that maintains a stack-based history of child widgets; Dart’s named arguments are the setters.
Sourcepub fn pages(self, pages: impl IntoIterator<Item = PageRef>) -> Navigator
pub fn pages(self, pages: impl IntoIterator<Item = PageRef>) -> Navigator
Dart Navigator(pages:).
Sourcepub fn on_pop_page(
self,
on_pop_page: impl Fn(&mut App, AnyRoute, RouteResult) -> bool + 'static,
) -> Navigator
pub fn on_pop_page( self, on_pop_page: impl Fn(&mut App, AnyRoute, RouteResult) -> bool + 'static, ) -> Navigator
Dart Navigator(onPopPage:).
Sourcepub fn on_did_remove_page(
self,
on_did_remove_page: impl Fn(&mut App, PageRef) + 'static,
) -> Navigator
pub fn on_did_remove_page( self, on_did_remove_page: impl Fn(&mut App, PageRef) + 'static, ) -> Navigator
Dart Navigator(onDidRemovePage:).
Sourcepub fn transition_delegate(self, delegate: TransitionDelegateRef) -> Navigator
pub fn transition_delegate(self, delegate: TransitionDelegateRef) -> Navigator
Dart Navigator(transitionDelegate:).
Sourcepub fn initial_route(self, initial_route: impl Into<String>) -> Navigator
pub fn initial_route(self, initial_route: impl Into<String>) -> Navigator
Dart Navigator(initialRoute:).
Sourcepub fn on_generate_route(
self,
on_generate_route: impl Fn(&mut App, &RouteSettings) -> Option<RouteRef> + 'static,
) -> Navigator
pub fn on_generate_route( self, on_generate_route: impl Fn(&mut App, &RouteSettings) -> Option<RouteRef> + 'static, ) -> Navigator
Dart Navigator(onGenerateRoute:).
Sourcepub fn on_unknown_route(
self,
on_unknown_route: impl Fn(&mut App, &RouteSettings) -> Option<RouteRef> + 'static,
) -> Navigator
pub fn on_unknown_route( self, on_unknown_route: impl Fn(&mut App, &RouteSettings) -> Option<RouteRef> + 'static, ) -> Navigator
Dart Navigator(onUnknownRoute:).
Sourcepub fn observers(
self,
observers: impl IntoIterator<Item = NavigatorObserverRef>,
) -> Navigator
pub fn observers( self, observers: impl IntoIterator<Item = NavigatorObserverRef>, ) -> Navigator
Dart Navigator(observers:).
Sourcepub fn restoration_scope_id(
self,
restoration_scope_id: impl Into<String>,
) -> Navigator
pub fn restoration_scope_id( self, restoration_scope_id: impl Into<String>, ) -> Navigator
Dart Navigator(restorationScopeId:).
Sourcepub fn route_traversal_edge_behavior(
self,
behavior: TraversalEdgeBehavior,
) -> Navigator
pub fn route_traversal_edge_behavior( self, behavior: TraversalEdgeBehavior, ) -> Navigator
Dart Navigator(routeTraversalEdgeBehavior:).
Sourcepub fn route_directional_traversal_edge_behavior(
self,
behavior: TraversalEdgeBehavior,
) -> Navigator
pub fn route_directional_traversal_edge_behavior( self, behavior: TraversalEdgeBehavior, ) -> Navigator
Dart Navigator(routeDirectionalTraversalEdgeBehavior:).
Sourcepub fn on_generate_initial_routes(
self,
on_generate_initial_routes: impl Fn(&mut App, Handle<NavigatorState>, &str) -> Vec<RouteRef> + 'static,
) -> Navigator
pub fn on_generate_initial_routes( self, on_generate_initial_routes: impl Fn(&mut App, Handle<NavigatorState>, &str) -> Vec<RouteRef> + 'static, ) -> Navigator
Dart Navigator(onGenerateInitialRoutes:).
Sourcepub fn reports_route_update_to_engine(self, value: bool) -> Navigator
pub fn reports_route_update_to_engine(self, value: bool) -> Navigator
Dart Navigator(reportsRouteUpdateToEngine:).
Sourcepub fn clip_behavior(self, clip_behavior: Clip) -> Navigator
pub fn clip_behavior(self, clip_behavior: Clip) -> Navigator
Dart Navigator(clipBehavior:).
Sourcepub fn request_focus(self, request_focus: bool) -> Navigator
pub fn request_focus(self, request_focus: bool) -> Navigator
Dart Navigator(requestFocus:).
Sourcepub fn of(
app: &mut App,
context: BuildContext,
root_navigator: bool,
) -> Handle<NavigatorState>
pub fn of( app: &mut App, context: BuildContext, root_navigator: bool, ) -> Handle<NavigatorState>
The state from the closest instance of this class that encloses the given context.
If root_navigator is set to true, the state from the furthest instance of this class is
given instead. Useful for pushing contents above all subsequent instances of
Navigator.
Panics if there is no Navigator in the given context.
Sourcepub fn maybe_of(
app: &mut App,
context: BuildContext,
root_navigator: bool,
) -> Option<Handle<NavigatorState>>
pub fn maybe_of( app: &mut App, context: BuildContext, root_navigator: bool, ) -> Option<Handle<NavigatorState>>
The state from the closest instance of this class that encloses the given context, if any.
If root_navigator is set to true, the state from the furthest instance of this class is
given instead.
Sourcepub fn push_named(
app: &mut App,
context: BuildContext,
route_name: &str,
arguments: Option<Rc<dyn Any>>,
) -> CompleterFuture<RouteResult> ⓘ
pub fn push_named( app: &mut App, context: BuildContext, route_name: &str, arguments: Option<Rc<dyn Any>>, ) -> CompleterFuture<RouteResult> ⓘ
Push a named route onto the navigator that most tightly encloses the given context.
Returns a future that completes to the result value passed to pop when
the pushed route is popped off the navigator.
Sourcepub fn restorable_push_named(
app: &mut App,
context: BuildContext,
route_name: &str,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_push_named( app: &mut App, context: BuildContext, route_name: &str, arguments: Option<RestorationData>, ) -> String
Push a named route onto the navigator that most tightly encloses the given context, and return its restoration ID.
Sourcepub fn push_replacement_named(
app: &mut App,
context: BuildContext,
route_name: &str,
result: RouteResult,
arguments: Option<Rc<dyn Any>>,
) -> CompleterFuture<RouteResult> ⓘ
pub fn push_replacement_named( app: &mut App, context: BuildContext, route_name: &str, result: RouteResult, arguments: Option<Rc<dyn Any>>, ) -> CompleterFuture<RouteResult> ⓘ
Replace the current route of the navigator that most tightly encloses the given context by
pushing the route named route_name and then disposing the previous route once the
animation has completed.
Sourcepub fn restorable_push_replacement_named(
app: &mut App,
context: BuildContext,
route_name: &str,
result: RouteResult,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_push_replacement_named( app: &mut App, context: BuildContext, route_name: &str, result: RouteResult, arguments: Option<RestorationData>, ) -> String
The restorable version of push_replacement_named.
Sourcepub fn pop_and_push_named(
app: &mut App,
context: BuildContext,
route_name: &str,
result: RouteResult,
arguments: Option<Rc<dyn Any>>,
) -> CompleterFuture<RouteResult> ⓘ
pub fn pop_and_push_named( app: &mut App, context: BuildContext, route_name: &str, result: RouteResult, arguments: Option<Rc<dyn Any>>, ) -> CompleterFuture<RouteResult> ⓘ
Pop the current route off the navigator that most tightly encloses the given context and push a named route in its place.
Sourcepub fn restorable_pop_and_push_named(
app: &mut App,
context: BuildContext,
route_name: &str,
result: RouteResult,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_pop_and_push_named( app: &mut App, context: BuildContext, route_name: &str, result: RouteResult, arguments: Option<RestorationData>, ) -> String
The restorable version of pop_and_push_named.
Sourcepub fn push_named_and_remove_until(
app: &mut App,
context: BuildContext,
new_route_name: &str,
predicate: RoutePredicate,
arguments: Option<Rc<dyn Any>>,
) -> CompleterFuture<RouteResult> ⓘ
pub fn push_named_and_remove_until( app: &mut App, context: BuildContext, new_route_name: &str, predicate: RoutePredicate, arguments: Option<Rc<dyn Any>>, ) -> CompleterFuture<RouteResult> ⓘ
Push the route with the given name onto the navigator that most tightly encloses the
given context, and then remove all the previous routes until the predicate returns true.
Sourcepub fn restorable_push_named_and_remove_until(
app: &mut App,
context: BuildContext,
new_route_name: &str,
predicate: RoutePredicate,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_push_named_and_remove_until( app: &mut App, context: BuildContext, new_route_name: &str, predicate: RoutePredicate, arguments: Option<RestorationData>, ) -> String
The restorable version of
push_named_and_remove_until.
Sourcepub fn push(
app: &mut App,
context: BuildContext,
route: RouteRef,
) -> CompleterFuture<RouteResult> ⓘ
pub fn push( app: &mut App, context: BuildContext, route: RouteRef, ) -> CompleterFuture<RouteResult> ⓘ
Push the given route onto the navigator that most tightly encloses the given context.
Returns a future that completes to the result value passed to pop when
the pushed route is popped off the navigator.
Sourcepub fn restorable_push(
app: &mut App,
context: BuildContext,
route_builder: RestorableRouteBuilder,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_push( app: &mut App, context: BuildContext, route_builder: RestorableRouteBuilder, arguments: Option<RestorationData>, ) -> String
Push a new route onto the navigator that most tightly encloses the given context, and return its restoration ID.
Sourcepub fn push_replacement(
app: &mut App,
context: BuildContext,
new_route: RouteRef,
result: RouteResult,
) -> CompleterFuture<RouteResult> ⓘ
pub fn push_replacement( app: &mut App, context: BuildContext, new_route: RouteRef, result: RouteResult, ) -> CompleterFuture<RouteResult> ⓘ
Replace the current route of the navigator that most tightly encloses the given context by pushing the given route and then disposing the previous route.
Sourcepub fn restorable_push_replacement(
app: &mut App,
context: BuildContext,
route_builder: RestorableRouteBuilder,
result: RouteResult,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_push_replacement( app: &mut App, context: BuildContext, route_builder: RestorableRouteBuilder, result: RouteResult, arguments: Option<RestorationData>, ) -> String
The restorable version of push_replacement.
Sourcepub fn push_and_remove_until(
app: &mut App,
context: BuildContext,
new_route: RouteRef,
predicate: RoutePredicate,
) -> CompleterFuture<RouteResult> ⓘ
pub fn push_and_remove_until( app: &mut App, context: BuildContext, new_route: RouteRef, predicate: RoutePredicate, ) -> CompleterFuture<RouteResult> ⓘ
Push the given route onto the navigator that most tightly encloses the given context, and
then remove all the previous routes until the predicate returns true.
Sourcepub fn restorable_push_and_remove_until(
app: &mut App,
context: BuildContext,
new_route_builder: RestorableRouteBuilder,
predicate: RoutePredicate,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_push_and_remove_until( app: &mut App, context: BuildContext, new_route_builder: RestorableRouteBuilder, predicate: RoutePredicate, arguments: Option<RestorationData>, ) -> String
The restorable version of push_and_remove_until.
Sourcepub fn replace(
app: &mut App,
context: BuildContext,
old_route: AnyRoute,
new_route: RouteRef,
)
pub fn replace( app: &mut App, context: BuildContext, old_route: AnyRoute, new_route: RouteRef, )
Replaces a route on the navigator that most tightly encloses the given context with a new route.
Sourcepub fn restorable_replace(
app: &mut App,
context: BuildContext,
old_route: AnyRoute,
new_route_builder: RestorableRouteBuilder,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_replace( app: &mut App, context: BuildContext, old_route: AnyRoute, new_route_builder: RestorableRouteBuilder, arguments: Option<RestorationData>, ) -> String
The restorable version of replace.
Sourcepub fn replace_route_below(
app: &mut App,
context: BuildContext,
anchor_route: AnyRoute,
new_route: RouteRef,
)
pub fn replace_route_below( app: &mut App, context: BuildContext, anchor_route: AnyRoute, new_route: RouteRef, )
Replaces a route on the navigator that most tightly encloses the given context with a new
route. The route to be replaced is the one below the given anchor_route.
Sourcepub fn restorable_replace_route_below(
app: &mut App,
context: BuildContext,
anchor_route: AnyRoute,
new_route_builder: RestorableRouteBuilder,
arguments: Option<RestorationData>,
) -> String
pub fn restorable_replace_route_below( app: &mut App, context: BuildContext, anchor_route: AnyRoute, new_route_builder: RestorableRouteBuilder, arguments: Option<RestorationData>, ) -> String
The restorable version of replace_route_below.
Sourcepub fn can_pop(app: &mut App, context: BuildContext) -> bool
pub fn can_pop(app: &mut App, context: BuildContext) -> bool
Whether the navigator that most tightly encloses the given context can be popped.
The initial route cannot be popped off the navigator, which implies that this function returns true only if popping the navigator would not remove the initial route.
Sourcepub fn maybe_pop(
app: &mut App,
context: BuildContext,
result: RouteResult,
) -> bool
pub fn maybe_pop( app: &mut App, context: BuildContext, result: RouteResult, ) -> bool
Consults the current route’s AnyRoute::pop_disposition method, and acts accordingly,
potentially popping the route as a result; returns whether the pop request should be
considered handled.
Sourcepub fn pop(app: &mut App, context: BuildContext, result: RouteResult)
pub fn pop(app: &mut App, context: BuildContext, result: RouteResult)
Pop the top-most route off the navigator that most tightly encloses the given context.
Sourcepub fn pop_until(
app: &mut App,
context: BuildContext,
predicate: RoutePredicate,
)
pub fn pop_until( app: &mut App, context: BuildContext, predicate: RoutePredicate, )
Calls pop repeatedly on the navigator that most tightly encloses the given
context until the predicate returns true.
Sourcepub fn pop_until_with_result(
app: &mut App,
context: BuildContext,
predicate: RoutePredicate,
result: RouteResult,
)
pub fn pop_until_with_result( app: &mut App, context: BuildContext, predicate: RoutePredicate, result: RouteResult, )
Calls pop repeatedly until the predicate returns true, passing result to
the last popped route.
Sourcepub fn remove_route(
app: &mut App,
context: BuildContext,
route: AnyRoute,
result: RouteResult,
)
pub fn remove_route( app: &mut App, context: BuildContext, route: AnyRoute, result: RouteResult, )
Immediately remove route from the navigator that most tightly encloses the given
context, and dispose of it.
Sourcepub fn remove_route_below(
app: &mut App,
context: BuildContext,
anchor_route: AnyRoute,
result: RouteResult,
)
pub fn remove_route_below( app: &mut App, context: BuildContext, anchor_route: AnyRoute, result: RouteResult, )
Immediately remove a route from the navigator that most tightly encloses the given
context, and dispose of it. The route to be replaced is the one below the given
anchor_route.
Sourcepub fn default_generate_initial_routes(
app: &mut App,
navigator: Handle<NavigatorState>,
initial_route_name: &str,
) -> Vec<RouteRef>
pub fn default_generate_initial_routes( app: &mut App, navigator: Handle<NavigatorState>, initial_route_name: &str, ) -> Vec<RouteRef>
Turn a route name into a set of Route objects.
This is the default value of on_generate_initial_routes,
which is used if that value is not supplied.
If the route name starts with / and is longer than one character, the name is split on
/ characters and each prefix is pushed in turn.
Trait Implementations§
Source§type State = NavigatorState
type State = NavigatorState
Source§fn create_state(&self) -> NavigatorState
fn create_state(&self) -> NavigatorState
Source§fn debug_fill_properties(
&self,
_app: &App,
properties: &mut DiagnosticPropertiesBuilder,
)
fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )
debugFillProperties: the properties a dump shows for this widget, in Dart’s
order. Dart’s Widget base only sets the dense tree style, which the framework does.Source§fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>
Source§fn type_name(&self) -> &'static str
fn type_name(&self) -> &'static str
Widget::type_name. A stateful form another widget kind becomes (an animated or
status transition widget) names the widget it wraps.Auto Trait Implementations§
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
impl<W> IntoWidget<StatefulKind> for Wwhere
W: StatefulWidget,
Source§fn into_widget(self) -> Rc<dyn Widget>
fn into_widget(self) -> Rc<dyn Widget>
creation_location.