args<T extends NyArgument?> static method

T? args<T extends NyArgument?>(
  1. BuildContext context
)

Retrieves the arguments passed in when calling the navigate function.

Returned arguments are casted with the type provided, the type will always be a subtype of NyArgument.

Make sure to provide the appropriate type, that is, provide the same type as the one passed while calling navigate, else a cast error will be thrown.

Implementation

static T? args<T extends NyArgument?>(BuildContext context) {
  final route = ModalRoute.of(context);
  if (route == null) return null;
  final arguments = route.settings.arguments;
  if (arguments is! ArgumentsWrapper) return null;
  return arguments.baseArguments as T?;
}