Duplicate values with Drift and Riverpod family stream #3496
Replies: 1 comment 1 reply
-
This is more of a Riverpod question. There many things wrong with your code.
@riverpod
class CharacterLocationStream extends _$CharacterLocationStream {
@override
Stream<String> build({required String characterId}) {
final activeCharacterRepository =
ref.watch(activeCharacterRepositoryProvider);
return activeCharacterRepository
.watchCharacterLocation(characterId: characterId)
.distinct();
}
} Now Riverpod will cancel the stream when it's disposed |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have the following stream in the Drift repository:
I subscribe to it with this provider (not simplified because of the debug logging):
The first time this is run with character A, it works properly. If I then switch to character B, the old provider is disposed, a new provider is created, but now when character B's locationId changes, I get notified twice, once for character A and once for character B:
If I switch from character A to character A, the provider gets disposed and rebuilt with the same hashcode, but when character A's locationId changes I get notified twice.
Am I somehow supposed to stop listening to the Drift stream manually when the provider is disposed?
Beta Was this translation helpful? Give feedback.
All reactions