entry<T extends ContextEntry> method

T? entry<T extends ContextEntry>([
  1. T? defaultValue
])

Retrieves an entry from Context by type T.

If entry is not present in the Context, the defaultValue is returned.

If provided, defaultValue must exactly match the return type T.

Implementation

T? entry<T extends ContextEntry>([T? defaultValue]) {
  if (defaultValue != null && T != defaultValue.runtimeType) {
    throw ArgumentError.value(
      defaultValue,
      "defaultValue",
      "does not match the expected return type '${T}'",
    );
  }
  return _context.containsKey(T) ? _context[T] as T? : defaultValue;
}