get<T> method

T? get<T>(
  1. ContextKey<T> key
)

Gets the value added for the ContextKey Returns null if no value is set for this key or if the value's type doesn't match T Gets a value from the context for the specified key.

Returns null if the key is not present or if the value's type doesn't match T. This prevents type casting errors when retrieving values.

Implementation

T? get<T>(ContextKey<T> key) {
  final value = _values[key];
  if (value == null) return null;
  if (value is T) return value as T;
  return null; // Return null when types don't match instead of throwing
}