close method
Closes the event and state Streams.
This method should be called when a Bloc is no longer needed.
Once close is called, events that are added will not be
processed.
In addition, if close is called while events are still being
processed, the Bloc will finish processing the pending events.
Implementation
@override
Future<void> close() {
// Cancel timers
_typingDebounceTimer?.cancel();
_batchEmitTimer?.cancel();
_pendingEvents.clear();
_conversationIndexMap.clear();
// Dispose typing notifiers
for (final notifier in _typingNotifiers.values) {
notifier.dispose();
}
_typingNotifiers.clear();
// Remove SDK listeners
CometChat.removeMessageListener(_messageListenerKey);
if (usersStatusVisibility) {
CometChat.removeUserListener(_userListenerKey);
}
CometChat.removeGroupListener(_groupListenerKey);
CometChat.removeCallListener(_callListenerKey);
CometChat.removeConnectionListener(_connectionListenerKey);
// Remove CC UI Event listeners
CometChatMessageEvents.removeMessagesListener(_ccMessageListenerKey);
CometChatGroupEvents.removeGroupsListener(_ccGroupListenerKey);
CometChatConversationEvents.removeConversationListListener(
_ccConversationListenerKey);
_isLoadingMore = false;
return super.close();
}