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.


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