Skip to content

Commit 4f9c683

Browse files
fix: 🐛 prevent actions if receiver is not capable of dealing with them
1 parent 232214c commit 4f9c683

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

lib/src/controller/chat_controller.dart

+11-6
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ class ChatController {
8585
/// Used to add message in message list.
8686
void addMessage(Message message) {
8787
initialMessageList.add(message);
88-
messageStreamController.sink.add(initialMessageList);
88+
if (!messageStreamController.isClosed) {
89+
messageStreamController.sink.add(initialMessageList);
90+
}
8991
}
9092

9193
/// Used to add reply suggestions.
@@ -136,11 +138,14 @@ class ChatController {
136138
/// Function to scroll to last messages in chat view
137139
void scrollToLastMessage() => Timer(
138140
const Duration(milliseconds: 300),
139-
() => scrollController.animateTo(
140-
scrollController.position.minScrollExtent,
141-
curve: Curves.easeIn,
142-
duration: const Duration(milliseconds: 300),
143-
),
141+
() {
142+
if (!scrollController.hasClients) return;
143+
scrollController.animateTo(
144+
scrollController.position.minScrollExtent,
145+
curve: Curves.easeIn,
146+
duration: const Duration(milliseconds: 300),
147+
);
148+
},
144149
);
145150

146151
/// Function for loading data while pagination.

0 commit comments

Comments
 (0)