Skip to main content

Navigator

Struct Navigator 

Source
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>§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: TransitionDelegateRef

The 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: TraversalEdgeBehavior

Controls 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: TraversalEdgeBehavior

Controls 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: RouteListFactory

Called 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: bool

Whether this navigator should report route update message back to the engine when the top-most route changes.

§clip_behavior: Clip

The content will be clipped (or not) according to this option.

Defaults to Clip::HardEdge.

§request_focus: bool

Whether 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§

Source§

impl Navigator

Source

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.
Source

pub fn new() -> Navigator

Creates a widget that maintains a stack-based history of child widgets; Dart’s named arguments are the setters.

Source

pub fn key(self, key: KeyRef) -> Navigator

Dart Navigator(key:).

Source

pub fn pages(self, pages: impl IntoIterator<Item = PageRef>) -> Navigator

Dart Navigator(pages:).

Source

pub fn on_pop_page( self, on_pop_page: impl Fn(&mut App, AnyRoute, RouteResult) -> bool + 'static, ) -> Navigator

Dart Navigator(onPopPage:).

Source

pub fn on_did_remove_page( self, on_did_remove_page: impl Fn(&mut App, PageRef) + 'static, ) -> Navigator

Dart Navigator(onDidRemovePage:).

Source

pub fn transition_delegate(self, delegate: TransitionDelegateRef) -> Navigator

Dart Navigator(transitionDelegate:).

Source

pub fn initial_route(self, initial_route: impl Into<String>) -> Navigator

Dart Navigator(initialRoute:).

Source

pub fn on_generate_route( self, on_generate_route: impl Fn(&mut App, &RouteSettings) -> Option<RouteRef> + 'static, ) -> Navigator

Dart Navigator(onGenerateRoute:).

Source

pub fn on_unknown_route( self, on_unknown_route: impl Fn(&mut App, &RouteSettings) -> Option<RouteRef> + 'static, ) -> Navigator

Dart Navigator(onUnknownRoute:).

Source

pub fn observers( self, observers: impl IntoIterator<Item = NavigatorObserverRef>, ) -> Navigator

Dart Navigator(observers:).

Source

pub fn restoration_scope_id( self, restoration_scope_id: impl Into<String>, ) -> Navigator

Dart Navigator(restorationScopeId:).

Source

pub fn route_traversal_edge_behavior( self, behavior: TraversalEdgeBehavior, ) -> Navigator

Dart Navigator(routeTraversalEdgeBehavior:).

Source

pub fn route_directional_traversal_edge_behavior( self, behavior: TraversalEdgeBehavior, ) -> Navigator

Dart Navigator(routeDirectionalTraversalEdgeBehavior:).

Source

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:).

Source

pub fn reports_route_update_to_engine(self, value: bool) -> Navigator

Dart Navigator(reportsRouteUpdateToEngine:).

Source

pub fn clip_behavior(self, clip_behavior: Clip) -> Navigator

Dart Navigator(clipBehavior:).

Source

pub fn request_focus(self, request_focus: bool) -> Navigator

Dart Navigator(requestFocus:).

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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§

impl Debug for Navigator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Navigator

Source§

fn default() -> Navigator

Returns the “default value” for a type. Read more
Source§

impl StatefulWidget for Navigator

Source§

type State = NavigatorState

The state this widget creates.
Source§

fn key(&self) -> Option<&KeyRef>

Source§

fn create_state(&self) -> NavigatorState

Creates the mutable state for this widget at a given location in the tree. Read more
Source§

fn debug_fill_properties( &self, _app: &App, properties: &mut DiagnosticPropertiesBuilder, )

Dart’s 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 debug_check_constructor(&self)

Source§

fn as_preferred_size_widget(&self) -> Option<&dyn PreferredSizeWidget>

Source§

fn type_name(&self) -> &'static str

See Widget::type_name. A stateful form another widget kind becomes (an animated or status transition widget) names the widget it wraps.

Auto Trait Implementations§

§

impl !RefUnwindSafe for Navigator

§

impl !Send for Navigator

§

impl !Sync for Navigator

§

impl !UnwindSafe for Navigator

§

impl Forget for Navigator

§

impl Freeze for Navigator
where *const RcInner<dyn Key> is !null: Freeze, PhantomData<RcInner<dyn Key>>: Freeze, *const u8 is !null: Freeze, PhantomData<Rc<dyn Page>>: Freeze, *const RcInner<dyn Fn(&mut App, AnyRoute, Option<Rc<dyn Any>>) -> bool> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, AnyRoute, Option<Rc<dyn Any>>) -> bool>>: Freeze, *const RcInner<dyn Fn(&mut App, Rc<dyn Page>)> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, Rc<dyn Page>)>>: Freeze, *const RcInner<dyn TransitionDelegate> is !null: Freeze, PhantomData<RcInner<dyn TransitionDelegate>>: Freeze, PhantomData<u8>: Freeze, *const RcInner<dyn Fn(&mut App, &RouteSettings) -> Option<Retained<AnyRoute>>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, &RouteSettings) -> Option<Retained<AnyRoute>>>>: Freeze, PhantomData<Retained<AnyNavigatorObserver>>: Freeze, *const RcInner<dyn Fn(&mut App, Handle<NavigatorState>, &str) -> Vec<Retained<AnyRoute>>> is !null: Freeze, PhantomData<RcInner<dyn Fn(&mut App, Handle<NavigatorState>, &str) -> Vec<Retained<AnyRoute>>>>: Freeze,

§

impl Move for Navigator

§

impl Unpin for Navigator
where Rc<dyn Key>: Unpin, *const u8 is !null: Unpin, Rc<dyn Page>: Unpin, Rc<dyn Fn(&mut App, AnyRoute, Option<Rc<dyn Any>>) -> bool>: Unpin, Rc<dyn Fn(&mut App, Rc<dyn Page>)>: Unpin, Rc<dyn TransitionDelegate>: Unpin, Rc<dyn Fn(&mut App, &RouteSettings) -> Option<Retained<AnyRoute>>>: Unpin, NonZero<u32>: Unpin, &'static NavigatorObserverVTable: Unpin, Rc<Keep>: Unpin, Rc<dyn Fn(&mut App, Handle<NavigatorState>, &str) -> Vec<Retained<AnyRoute>>>: Unpin,

§

impl UnsafeUnpin for Navigator
where *const RcInner<dyn Key> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Key>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Rc<dyn Page>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, AnyRoute, Option<Rc<dyn Any>>) -> bool> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, AnyRoute, Option<Rc<dyn Any>>) -> bool>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, Rc<dyn Page>)> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, Rc<dyn Page>)>>: UnsafeUnpin, *const RcInner<dyn TransitionDelegate> is !null: UnsafeUnpin, PhantomData<RcInner<dyn TransitionDelegate>>: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, &RouteSettings) -> Option<Retained<AnyRoute>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, &RouteSettings) -> Option<Retained<AnyRoute>>>>: UnsafeUnpin, PhantomData<Retained<AnyNavigatorObserver>>: UnsafeUnpin, *const RcInner<dyn Fn(&mut App, Handle<NavigatorState>, &str) -> Vec<Retained<AnyRoute>>> is !null: UnsafeUnpin, PhantomData<RcInner<dyn Fn(&mut App, Handle<NavigatorState>, &str) -> Vec<Retained<AnyRoute>>>>: UnsafeUnpin,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<W> IntoWidget<StatefulKind> for W
where W: StatefulWidget,

Source§

fn into_widget(self) -> Rc<dyn Widget>

The widget as a tree node, made where this is called: its creation_location.
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>