watch static method
SingleChildStatelessWidget
watch({
- Key? key,
- void onDisappear(
- BuildContext context
- void onAppear(
- BuildContext context,
- DeepLinkParam? deepLinkParam
- 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:
- When the route is first pushed onto the navigation stack.
- 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,
);
}