From 0117e4cb7c18fdf1620a0143cb8c676d46ac74fc Mon Sep 17 00:00:00 2001 From: Sahil Kumar Date: Tue, 16 Aug 2022 15:32:10 +0530 Subject: [PATCH] fix(core): use copyWith while setting controller items. Signed-off-by: xsahil03x --- packages/stream_chat_flutter_core/CHANGELOG.md | 2 ++ .../lib/src/stream_channel_list_controller.dart | 13 +++++++------ .../lib/src/stream_user_list_controller.dart | 13 +++++++------ 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/packages/stream_chat_flutter_core/CHANGELOG.md b/packages/stream_chat_flutter_core/CHANGELOG.md index 3d6aa989..5335a023 100644 --- a/packages/stream_chat_flutter_core/CHANGELOG.md +++ b/packages/stream_chat_flutter_core/CHANGELOG.md @@ -2,6 +2,8 @@ - [#1269](https://github.com/GetStream/stream-chat-flutter/issues/1269) Fix `ChannelListEventHandler` castError at PagedValue.asSuccess. +- [#1241](https://github.com/GetStream/stream-chat-flutter/issues/1241) StreamChannelListView load + more indicator non stop. ## 4.4.1 diff --git a/packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart b/packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart index bea403be..7cd425a6 100644 --- a/packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart +++ b/packages/stream_chat_flutter_core/lib/src/stream_channel_list_controller.dart @@ -163,13 +163,14 @@ class StreamChannelListController extends PagedValueNotifier { } } - /// Replaces the previously loaded channels with [channels] and updates - /// the nextPageKey. + /// Replaces the previously loaded channels with the passed [channels]. set channels(List channels) { - value = PagedValue( - items: channels, - nextPageKey: channels.length, - ); + if (value.isSuccess) { + final currentValue = value.asSuccess; + value = currentValue.copyWith(items: channels); + } else { + value = PagedValue(items: channels); + } } /// Returns/Creates a new Channel and starts watching it. diff --git a/packages/stream_chat_flutter_core/lib/src/stream_user_list_controller.dart b/packages/stream_chat_flutter_core/lib/src/stream_user_list_controller.dart index 3e1b2892..466b6177 100644 --- a/packages/stream_chat_flutter_core/lib/src/stream_user_list_controller.dart +++ b/packages/stream_chat_flutter_core/lib/src/stream_user_list_controller.dart @@ -153,12 +153,13 @@ class StreamUserListController extends PagedValueNotifier { return super.refresh(resetValue: resetValue); } - /// Replaces the previously loaded users with [users] and updates - /// the nextPageKey. + /// Replaces the previously loaded users with the passed [users]. set users(List users) { - value = PagedValue( - items: users, - nextPageKey: users.length, - ); + if (value.isSuccess) { + final currentValue = value.asSuccess; + value = currentValue.copyWith(items: users); + } else { + value = PagedValue(items: users); + } } }