Please look at the following pseudo code using Dart Riverpod.
final dependingStreamProvider = StreamProvider.autoDispose<int>((ref) {
final depending = ref.watch(dependingProvider);
if (depending == typeA) {
return AStream(); // returns stream of int
} else {
return BStream(); // returns a different stream of int
}
});
In this case, as dependingProvider
changes its status, the StreamProvider
creates another Stream
instance.
My question is, does the stale Stream
instance gets disposed of (i.e., its StreamController
gets close
d) by Riverpod? Or do we have to handle ourselves somehow?
I saw a similar question here: Do you have to manually dispose streams from a streamprovider in Flutter? but I wasn't quite sure if the accepted answer refers to my case above.
I understand that autoDispose
will take care of the disposal when there is nobody listening to the StreamProvider
itself, but the above case is a different case