getArgumentAndClean<T extends RouteParams?> method

T? getArgumentAndClean<T extends RouteParams?>({
  1. RouteSettings? settings,
})

Reads an argument of type T and immediately removes it from the current route's settings.

This method is designed for consuming one-time events, such as the result from a screen that was popped (context.pop(args: ...)). By removing the argument after reading, it prevents the same event from being processed again if the widget rebuilds.

It is best used within the onAppear callback of Browser.watch.

See also:

  • getArgument, for reading an argument without consuming it.

Implementation

T? getArgumentAndClean<T extends RouteParams?>({
  RouteSettings? settings,
}) {
  final arguments =
      settings?.arguments ?? ModalRoute.of(this)?.settings.arguments;

  if (arguments is! Map) return null;

  return arguments.getAndClean<T>();
}