$tryGetRouteParam<U> method

  1. @protected
  2. @nonVirtual
  3. @internal
U $tryGetRouteParam<U>(
  1. String key,
  2. U defaultValue
)
inherited

Implementation

@protected
@nonVirtual
@internal
U $tryGetRouteParam<U>(String key, U defaultValue) {
	if (this.widget.$hasWidgetWrapper()) {
		return this.widget.$getRouteParamFromWidgetWrapper(key);
	}

	ModalRoute? modelRoute = ModalRoute.of(this.context);
	if (modelRoute == null) {
		throw "Cannot access ModalRoute.of(this.context) in ${this} for key [${key}]";
	}

	Object? args = modelRoute.settings.arguments;
	if (args == null || args is! Map<String, dynamic>) {
		return defaultValue;
	}

	Map<String, dynamic> map = args;
	if (!map.containsKey(key)) {
		return defaultValue;
	}

	return map[key] as U;
}