Home > Net >  StreamUnreadIndicator does not update and displays nothing getStream Api
StreamUnreadIndicator does not update and displays nothing getStream Api

Time:07-16

I have had tough luck with the StreamUnreadIndicator() within the getStream API. I am trying to essentially have an indicator on the list tile for whenever a new message comes in. But nothing returns. I tried putting some debug prints to at least get the number of unread messages for the channel, but it is always 0.

Here's my message list view:

Widget _messagesList(List<dynamic>? messages, StreamChatClient client,
      int messageCount, bool friendsTab) {
    return ListView.separated(
      keyboardDismissBehavior: ScrollViewKeyboardDismissBehavior.onDrag,
      itemCount: messageCount,
      itemBuilder: (context, index) {
        //print("messaging:" messages![index].channel);
        return GestureDetector(
          onTap: () {
            Navigator.of(context).push(MaterialPageRoute(builder: (context) =>
                MessageApi(
                  sourceType: SourceType.justMet,
                  receiverUser: friendsTab ? friends[index] : chatRequesters[index],
                  userName: userName,
                  channelId: messages![index].channel,
                  streamToken: streamToken,
                  client: StreamChatCore.of(context).client,
                )
            ));
          },
          child: ListTile(
            title: friendsTab ? Text(friends[index].firstName) : Text(chatRequesters[index].firstName),
            subtitle: _buildLastMessage(messages![index].channel, client),
            trailing: Column(
              children: [
                StreamUnreadIndicator(
                  cid: "messaging:" messages[index].channel,
                ),
                _buildLastMessageAt(messages[index].channel, client),
              ],
            ),
            leading: CircleAvatar(
              radius: 30,
              backgroundImage: CachedNetworkImageProvider(
                  friendsTab ? friends[index].photoUrl : chatRequesters[index].photoUrl
              ),
            ),
          ),
        );
      },
      separatorBuilder: (context, index) {
        return const Divider();
      },
    );
  }

CodePudding user response:

Version 4.3 of Stream Chat Flutter introduced unreadMessagesSeparatorBuilder:

Try

StreamMessageListView(
  unreadMessagesSeparatorBuilder: (context, unreadCount) =>
      Text('$unreadCount unread message'),
)

See the changeling for additional details: https://pub.dev/packages/stream_chat_flutter/changelog

  • Related