read<Result> method Null safety

Result read<Result>(
  1. ProviderBase<Result> provider
)

Reads a provider without listening to it and returns the currently exposed value.

final greetingProvider = Provider((_) => 'Hello world');

void main() {
  final container = ProviderContainer();

  print(container.read(greetingProvider)); // Hello World
}

Implementation

Result read<Result>(
  ProviderBase<Result> provider,
) {
  final element = readProviderElement(provider);
  element.flush();

  // In case `read` was called on a provider that has no listener
  element.mayNeedDispose();

  return element.readSelf();
}