fix(core): only handle the channel list event if the state is success.

Signed-off-by: xsahil03x <[email protected]>
This commit is contained in:
Sahil Kumar
2022-08-08 15:11:28 +05:30
committed by xsahil03x
parent bd1876c159
commit 9fa5ac49d0
3 changed files with 42 additions and 19 deletions
@@ -111,6 +111,9 @@ abstract class PagedValue<Key, Value> with _$PagedValue<Key, Value> {
/// Returns `true` if the [PagedValue] is [Success].
bool get isSuccess => this is Success<Key, Value>;
/// Returns `true` if the [PagedValue] is not [Success].
bool get isNotSuccess => !isSuccess;
/// Returns the [PagedValue] as [Success].
Success<Key, Value> get asSuccess {
assert(
@@ -223,6 +223,9 @@ class StreamChannelListController extends PagedValueNotifier<int, Channel> {
client.on().skip(1) // Skipping the last emitted event.
// We only need to handle the latest events.
.listen((event) {
// Only handle the event if the value is in success state.
if (value.isNotSuccess) return;
// Returns early if the event is already handled by the listener.
if (eventListener?.call(event) ?? false) return;