watch static method

SingleChildStatelessWidget watch({
  1. Key? key,
  2. void onDisappear(
    1. BuildContext context
    )?,
  3. void onAppear(
    1. BuildContext context,
    2. DeepLinkParam? deepLinkParam
    )?,
  4. Widget? child,
})

Provides a widget that can listen to page appearance and disappearance events.

This is a convenience method that wraps your widget with a PageObserverProvider, allowing it to react when a route becomes visible or invisible.

The onAppear callback is triggered in two scenarios:

  1. When the route is first pushed onto the navigation stack.
  2. When a route on top of it is popped, making this route visible again.

onAppear is the ideal place to handle arguments passed from a previous route via context.pop(args: ...) or deep link parameters from the URL. Use context.getArgumentAndClean() within this callback to consume one-time events.

The onDisappear callback is triggered when this route is no longer visible, either because a new route was pushed on top of it or because it was popped.

Implementation

static SingleChildStatelessWidget watch({
  Key? key,
  void Function(BuildContext context)? onDisappear,
  void Function(
    BuildContext context,
    DeepLinkParam? deepLinkParam,
  )? onAppear,
  Widget? child,
}) {
  return PageObserverProvider(
    key: key,
    onAppear: onAppear,
    onDisappear: onDisappear,
    routeObserver: routeObserver,
    child: child,
  );
}