# markAsRead not working

**URL:** <https://community.sendbird.com/t/markasread-not-working/4365>\
**Category:** Flutter\
**Tags:** group-channel, message, chatsdk\
**Created:** [April 6, 2022, 10:09am UTC](https://community.sendbird.com/t/markasread-not-working/4365 "2022-04-06T10:09:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GR\_GD](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/gr_gd/32/2306_2.png) [@GR\_GD](https://community.sendbird.com/u/GR_GD)\
**Post date:** [April 6, 2022, 10:09am UTC](https://community.sendbird.com/t/markasread-not-working/4365/1 "2022-04-06T10:09:48Z")

</div>

Hello,

I can send chat messages to multiple users on several devices using group channels.  
When the app resumes and when a new message is received, I use `channel.markAsRead();`

If I put a breakpoint in that method on the line `await _sdk.cmdManager.sendCommand(cmd);` I can see it triggers the breakpoint.

But `onReadReceiptUpdated` is not called (or very sporadically, might as well be never) on the other devices.  
`onMessageReceived` does work.

My `onMessageReceived` looks like this

```auto
  @override
  void onMessageReceived(BaseChannel channel, BaseMessage message) async {
    print('NEW: ${message.message}');

    _showMessage(
      message.message,
      types.User(id: message.sender!.userId),
      id: message.messageId,
      createdAt: message.createdAt,
      skipState: false,
    );

    this.channel!.markAsRead();
  }

```

The message is shown, so that code works, only `markAsRead` is not doing anything.  
I have tested on Android, iPad and web.

On Android I implemented push notifications, if I put the app in the background I get a push with the messages I missed.

Am I doing something wrong?

Thanks in advance

---

<div class="post-metadata">

**Author:** ![GR\_GD](https://sea2.discourse-cdn.com/flex020/user_avatar/community.sendbird.com/gr_gd/32/2306_2.png) [@GR\_GD](https://community.sendbird.com/u/GR_GD)\
**Post date:** [April 6, 2022, 12:28pm UTC](https://community.sendbird.com/t/markasread-not-working/4365/2 "2022-04-06T12:28:22Z")

</div>

Okay, I figured out what I was doing wrong.  
When the app goes in the background, or for other reasons, the connection can be dropped.  
You can only mark messages as read when the connection is `open`.

So I needed to implement `ConnectionEventHandler` to check when the connection is working again.  
`sendbird.addConnectionEventHandler(kConnectionEventHandler, this);`

I also mark as read after getting the channel:

```auto
channel = await GroupChannel.getChannel(tecClientSession.text);
_sendMarkAsRead();

```

Implementation of this handler:

```auto
  @override
  void onReconnectionSucceeded() {
    _sendMarkAsRead();
  }

  void _sendMarkAsRead() {
    if (sendbird.getConnectionState() == sendbirdSdk.ConnectionState.open) {
      channel?.markAsRead();
    }
  }

```
