getArgumentFromMap<T> method

T? getArgumentFromMap<T>(
  1. BuildContext context,
  2. String key
)

Retrieves an argument of type T from the route's argument map using the given key.

This method is useful for retrieving arguments passed during navigation. Returns the argument value if found, or null if the argument is not found or is of the wrong type.

Implementation

T? getArgumentFromMap<T>(BuildContext context, String key) {
  var argument = ModalRoute.of(context)!.settings.arguments;
  if (argument == null || argument is! Map) {
    return null;
  }
  Map<String, Object?> argMap = argument as Map<String, Object?>;
  return argMap[key] as T?;
}