useContextOrNull<T> function

T? useContextOrNull<T>()

Retrieves a provided value of type T, or null if not found.

final theme = useContextOrNull<ThemeData>();
if (theme != null) { ... }

Implementation

T? useContextOrNull<T>() {
  final stack = _contextStack[T];
  if (stack == null || stack.isEmpty) return null;
  return stack.last as T;
}