ImplicitNavigator<T> class

Pushes and pops pages from an internal navigator in response to changing app state.

When ImplicitNavigator is rebuilt with a new value and/or depth, 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, set maintainHistory to true and 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, valueAfterPop) => _index = valueAfterPop,
  );
}
Inheritance

Constructors

ImplicitNavigator({Key? key, bool maintainHistory = false, required T value, int? depth, List<ValueHistoryEntry<T>>? initialHistory, required AnimatedValueWidgetBuilder<T> builder, RouteTransitionsBuilder transitionsBuilder = defaultRouteTransitionsBuilder, Duration transitionDuration = _kDefaultTransitionDuration, required void onPop(T poppedValue, T valueAfterPop), bool takeFocus = false, bool maintainState = true, bool opaque = true, int? popPriority})
Create an implicit navigator directly from a value.
const

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?
Controls how one widget replaces another widget in the tree.
finalinherited
maintainHistory bool
Whether or not this widget should save and restore it's value history to page storage.
final
maintainState bool
Whether or not a page should be restored with its original state or rebuilt when a page on top of it is popped.
final
onPop → void Function(T poppedValue, T valueAfterPop)
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 Properties

displayBackButton ValueNotifier<bool>
final

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.
fromValueListenable<T>({Key? key, bool maintainHistory = false, required ValueListenable<T> valueListenable, int? getDepth(T value)?, List<ValueHistoryEntry<T>>? initialHistory, required AnimatedValueWidgetBuilder<T> builder, RouteTransitionsBuilder transitionsBuilder = defaultRouteTransitionsBuilder, Duration transitionDuration = _kDefaultTransitionDuration, required void onPop(T, T), bool takeFocus = false, bool maintainState = true, bool opaque = true, int? popPriority}) Widget
Creates an ImplicitNavigator that pushes new pages when the valueListenable changes and calls onPop when pages are popped.
fromValueNotifier<T>({Key? key, bool maintainHistory = false, required ValueNotifier<T> valueNotifier, int? getDepth(T value)?, List<ValueHistoryEntry<T>>? initialHistory, required AnimatedValueWidgetBuilder<T> builder, RouteTransitionsBuilder transitionsBuilder = defaultRouteTransitionsBuilder, Duration transitionDuration = _kDefaultTransitionDuration, void onPop(T, T)?, bool takeFocus = false, bool maintainState = true, bool opaque = true, int? popPriority}) Widget
Creates an ImplicitNavigator that pushes new pages when the valueNotifier changes and reverts valueNotifier.value when pages are popped.
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.
selectFromListenable<U extends Listenable, T>({Key? key, bool maintainHistory = false, required U listenable, required T selector(), int? getDepth(T value)?, List<ValueHistoryEntry<T>>? initialHistory, required AnimatedValueWidgetBuilder<T> builder, RouteTransitionsBuilder transitionsBuilder = defaultRouteTransitionsBuilder, Duration transitionDuration = _kDefaultTransitionDuration, required void onPop(T, T), bool takeFocus = false, bool maintainState = true, bool opaque = true, int? popPriority}) Widget
Creates an ImplicitNavigator that pushes new pages when a value selected from a listenable changes.