Home > Enterprise >  How to listen to changes on ProviderContainer in Riverpod?
How to listen to changes on ProviderContainer in Riverpod?

Time:11-18

In a context of pure Dart project I want to "watch" changes on dependencies. How do I listen to the changes?

As far as read() I am all fine i guess.

final container = ProviderContainer();
final dependency = container.read(myDependencyProvider);

CodePudding user response:

You need to extend ProviderObserver and override didUpdateProvider

ProviderObserver listens to the changes of a ProviderContainer.

Here is the official explanation

  • Related