According to the docs when I'm getting this error I am supposed to mark both Providers
with .autoDispose
:
The argument type 'AutoDisposeProvider' can't be assigned to the parameter type 'AlwaysAliveProviderBase'
Why am I still getting the error in this minimalistic example?
final a = FutureProvider.autoDispose<List<String>>((ref) {
return Future.value(["test"]);
});
final b = FutureProvider.autoDispose<List<String>>((ref) {
return ref.watch(a);
});
This error is happening because you tried to listen to a provider marked with .autoDispose in a provider that is not marked with .autoDispose.
final firstProvider = Provider.autoDispose((ref) => 0);
final secondProvider = Provider((ref) {
// The argument type 'AutoDisposeProvider<int>' can't be assigned to the
// parameter type 'AlwaysAliveProviderBase<Object, Null>'
ref.watch(firstProvider);
});
The solution is marking the secondProvider with .autoDispose.
final firstProvider = Provider.autoDispose((ref) => 0);
final secondProvider = Provider.autoDispose((ref) {
ref.watch(firstProvider);
});
I just copy the solution from the official Riverpod documentation at the bottom of the page: https://riverpod.dev/docs/concepts/modifiers/auto_dispose/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With