fromValueNotifier<T> static method

Widget fromValueNotifier<T>({
  1. Key? key,
  2. bool maintainHistory = false,
  3. required ValueNotifier<T> valueNotifier,
  4. int? getDepth(
    1. T value
    )?,
  5. List<ValueHistoryEntry<T>>? initialHistory,
  6. required AnimatedValueWidgetBuilder<T> builder,
  7. RouteTransitionsBuilder transitionsBuilder = defaultRouteTransitionsBuilder,
  8. Duration transitionDuration = _kDefaultTransitionDuration,
  9. void onPop(
    1. T,
    2. T
    )?,
  10. bool takeFocus = false,
  11. bool maintainState = true,
  12. bool opaque = true,
  13. int? popPriority,
})

Creates an ImplicitNavigator that pushes new pages when the valueNotifier changes and reverts valueNotifier.value when pages are popped.

If non-null, getDepth will be called on each value and used to set ImplicitNavigator.depth. getDepth MUST return the same depth for a given value every time it's called on that value. If it returns inconsistent depths, ImplicitNavigator may push redundant pages and will not pop pages properly.

Implementation

static Widget fromValueNotifier<T>({
  Key? key,
  bool maintainHistory = false,
  required ValueNotifier<T> valueNotifier,
  int? Function(T value)? getDepth,
  List<ValueHistoryEntry<T>>? initialHistory,
  required AnimatedValueWidgetBuilder<T> builder,
  RouteTransitionsBuilder transitionsBuilder = defaultRouteTransitionsBuilder,
  Duration transitionDuration = _kDefaultTransitionDuration,
  void Function(T, T)? onPop,
  bool takeFocus = false,
  bool maintainState = true,
  bool opaque = true,
  int? popPriority,
}) {
  return ValueListenableBuilder<T>(
    key: key,
    valueListenable: valueNotifier,
    builder: (context, value, child) {
      return ImplicitNavigator<T>(
        maintainHistory: maintainHistory,
        value: valueNotifier.value,
        depth: getDepth?.call(value),
        initialHistory: initialHistory,
        builder: builder,
        transitionsBuilder: transitionsBuilder,
        transitionDuration: transitionDuration,
        onPop: (poppedValue, valueAfterPop) {
          valueNotifier.value = valueAfterPop;
          onPop?.call(poppedValue, valueAfterPop);
        },
        takeFocus: takeFocus,
        maintainState: maintainState,
        opaque: opaque,
        popPriority: popPriority,
      );
    },
  );
}