read<T> method

T read<T>(
  1. ProviderListenable<T> provider
)

Read the value of the provider from the current ProviderContainer obtained from the surrounding ProviderScope.

This method does not establish a dependency on the ProviderScope. Therefore, if it is used inside a build method, it will not cause the widget to rebuild if the container changes.

This is best used in areas where a dependency is not necessary, such as a callback to a button press.

Implementation

T read<T>(ProviderListenable<T> provider) {
  final container = ProviderScope.containerOf(this, listen: false);
  return container.read(provider);
}