With the ChangeNotifierProvider
widget in Provider, you can call a method, say onInit(), immediately when a provider is created with create
like so
ChangeNotifierProvider(create: (_) => SomeChangeNotifier(context: context)..onInit();
What is the riverpod way of doing the same?
I tried
final exampleProvider = ChangeNotifierProvider.autoDispose<ExampleChangeNotifier>((ref) => ExampleChangeNotifier(providerRef: ref)..onInit());
thinking onInit()
will be called the first time exampleProvider
is read
or watch
ed in the build of a widget but it doesn't get called.