Search code examples
flutterdartriverpod

How to listen/write to a FutureProvider using providerContainer?


I have a FutureProvider, but I need to listen to it from outside the context, so I'm using the ProviderContainer for it.

final providerContainer = ProviderContainer();

final futureProvider = FutureProvider<String?>((ref) async {
  return await foo();
});

How do I get its value, and update it, using providerContainer?


Solution

  • The solution is given in the comments: it is not possible to access using the providerContainer since it is not the same instance. Instead, pass the WidgetRef to wherever you need to access the provider.