ImplicitNavigator<T> class
Pushes and pops pages from an internal navigator in response to changing app state.
When value and/or depth change, a new page is pushed onto the navigator
stack and builder is called with the latest value. When popFromTree
is
called or the system back button is pressed, ImplicitNavigator attempts to
pop from any navigator in the tree, starting with deepest nested navigator
first and breaking ties between equally deep navigators with popPriority.
Implicit Navigator can be used to produce two distinct navigation patterns:
- App-Style: the back button/pop goes "up" a developer defined navigation hierarchy, potentially undoing multiple state changes at once. App-style is typical for most modern smartphone apps.
- Browser-Style: the back button/pop reverts the last state change. Browser-style is how most web pages behave.
For app-style navigation, specify non-null values for depth to set your
app's navigation hierarchy. Additionally, provide a PageStorageKey
to any
ImplicitNavigator nested inside of another ImplicitNavigator.
This ensures that the history of the inner navigator is maintained when the
user navigates away form it and then back to it.
For browser-style navigation, simply leave depth null and do not provide
a PageStorageKey
to any nested ImplicitNavigator's.
The following code implements a trivial browser-style Implicit Navigator:
int _index = 0;
@override
Widget build(BuildContext context) {
return ImplicitNavigator<int>(
value: _index,
builder: (context, index, animation, secondaryAnimation) {
return TextButton(
onPressed: () => setState(() {
_index += 1;
}),
onLongPress: () => ImplicitNavigator.of(context).popFromTree()
child: Text(index.toString()),
);
},
onPop: (poppedValue, currentValue) => _index = currentValue,
);
}
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- ImplicitNavigator
Constructors
-
const
-
Creates an ImplicitNavigator that pushes new pages when the
valueNotifier
changes and revertsvalueNotifier.value
when pages are popped.
Properties
-
builder
→ AnimatedValueWidgetBuilder<
T> -
An animated build function that builds a widget from the given value.
final
- depth → int?
-
The depth of the current value.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
-
initialHistory
→ List<
ValueHistoryEntry< ?T> > -
A history stack to initialize this ImplicitNavigator with.
final
- key → Key?
-
See Widget.key.
final
- maintainState → bool
-
See ModalRoute.maintainState.
final
- onPop → (void Function(T poppedValue, T currentValue)?)
-
A callback that runs immediately after a page is popped.
final
- opaque → bool
-
See TransitionRoute.opaque.
final
- popPriority → int?
-
The priority of this widget when choosing which implicit navigator to pop
from.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- takeFocus → bool
-
Whether or not new routes pushed to
ImplicitNavigator
should request focus as they're pushed.final - transitionDuration → Duration
-
See TransitionRoute.transitionDuration.
final
- transitionsBuilder → RouteTransitionsBuilder
-
A function for animating the widget returned by builder in and out.
final
- value → T
-
The current value to build the navigator with.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → ImplicitNavigatorState -
Creates the mutable state for this widget at a given location in the tree.
override
-
debugDescribeChildren(
) → List< DiagnosticsNode> -
Returns a list of
DiagnosticsNode
objects describing this node's children.inherited -
debugFillProperties(
DiagnosticPropertiesBuilder properties) → void -
Add additional properties associated with the node.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toDiagnosticsNode(
{String? name, DiagnosticsTreeStyle? style}) → DiagnosticsNode -
Returns a debug representation of the object that is used by debugging
tools and by DiagnosticsNode.toStringDeep.
inherited
-
toString(
{DiagnosticLevel minLevel = DiagnosticLevel.info}) → String -
A string representation of this object.
inherited
-
toStringDeep(
{String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a string representation of this node and its descendants.
inherited
-
toStringShallow(
{String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) → String -
Returns a one-line detailed description of the object.
inherited
-
toStringShort(
) → String -
A short, textual description of this widget.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Methods
-
defaultRouteTransitionsBuilder(
BuildContext context, Animation< double> animation, Animation<double> secondaryAnimation, Widget child) → Widget - The default RouteTransitionsBuilder used by ImplicitNavigator to animate content in and out.
-
materialRouteTransitionsBuilder(
BuildContext context, Animation< double> animation, Animation<double> secondaryAnimation, Widget child) → Widget - A RouteTransitionsBuilder that uses the default transitions for the current platform.
-
of<
T> (BuildContext context, {bool root = false}) → ImplicitNavigatorState< T> - Get the nearest ancestor ImplicitNavigatorState in the widget tree.