GetStream / stream-chat-flutter

Flutter Chat SDK - Build your own chat app experience using Dart, Flutter and the Stream Chat Messaging API.
https://getstream.io/chat/sdk/flutter/
Other
930 stars 342 forks source link

StreamChatPersistenceClient.getChannelStates() issue #2034

Open sgowda97 opened 3 weeks ago

sgowda97 commented 3 weeks ago

Which packages are you using?

stream_chat_flutter, stream_chat_persistance

On what platforms did you experience the issue?

iOS, Android

What version are you using?

stream_chat_persistence: 8.1.0 stream_chat_flutter: 8.1.0

What happened?

Faster scrolling in the channel list page leads loadMoreIndicatorBuilder() to be displayed forever without displaying new paginated data.

Expected behaviour would be that the newly received paginated data should be displayed without any hiccups.

Steps to reproduce

1. Clone the example from stream_chat_flutter repo.
2. Run/debug the project with and without StreamChatPersistenceClient initialised.
3. Without the StreamChatPersistenceClient, scrolling fast in channel/chat list works fine.

Supporting info to reproduce

Further debugging led me to believe that the issue lies within getChannelStates() function of the StreamChatPersistenceClient. Starting at line 284 in stream_chat_persistence_client.dart,

final offset = paginationParams?.offset;
if (offset != null && offset > 0 && channelStates.isNotEmpty) {
  channelStates.removeRange(0, offset);
}

Occasionally, offset value is greater than channelStates.length, which leads to range error for channelStates.removeRange().

I believe this has something to do with the data fetched from DriftDatabase/moor. I tried logging channelStates.length and offset value, hence the range error:

flutter: statesLen: 30 || offset: 60

https://github.com/user-attachments/assets/2a7dcff0-b68d-4d50-a96b-7da744af0875

Relevant log output

No response

Flutter analyze output

No response

Flutter doctor output

No response

Code of Conduct

github-actions[bot] commented 2 days ago

This issue is stale because it has been open for 20 days with no activity.