Skip to content

Commit e3e154a

Browse files
jonasbadstuebneraditya-css
authored andcommitted
fix: 🐛 prevent actions if receiver is not capable of dealing with them
1 parent 08da145 commit e3e154a

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
send message not working when user start texting after newLine.
5151
* **Fix**: [191](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/191) Fix
5252
error when using `BuildContext` or `State` extensions when not mounted.
53+
* **Fix**: [192](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/192) Fix
54+
send to closed socket or animate on `ScrollController` without clients.
5355

5456
## [1.3.1]
5557

lib/src/controller/chat_controller.dart

+17-8
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ class ChatController {
8989
/// Used to add message in message list.
9090
void addMessage(Message message) {
9191
initialMessageList.add(message);
92-
messageStreamController.sink.add(initialMessageList);
92+
if (!messageStreamController.isClosed) {
93+
messageStreamController.sink.add(initialMessageList);
94+
}
9395
}
9496

9597
/// Used to add reply suggestions.
@@ -134,24 +136,31 @@ class ChatController {
134136
messageType: message.messageType,
135137
status: message.status,
136138
);
137-
messageStreamController.sink.add(initialMessageList);
139+
if (!messageStreamController.isClosed) {
140+
messageStreamController.sink.add(initialMessageList);
141+
}
138142
}
139143

140144
/// Function to scroll to last messages in chat view
141145
void scrollToLastMessage() => Timer(
142146
const Duration(milliseconds: 300),
143-
() => scrollController.animateTo(
144-
scrollController.position.minScrollExtent,
145-
curve: Curves.easeIn,
146-
duration: const Duration(milliseconds: 300),
147-
),
147+
() {
148+
if (!scrollController.hasClients) return;
149+
scrollController.animateTo(
150+
scrollController.position.minScrollExtent,
151+
curve: Curves.easeIn,
152+
duration: const Duration(milliseconds: 300),
153+
);
154+
},
148155
);
149156

150157
/// Function for loading data while pagination.
151158
void loadMoreData(List<Message> messageList) {
152159
/// Here, we have passed 0 index as we need to add data before first data
153160
initialMessageList.insertAll(0, messageList);
154-
messageStreamController.sink.add(initialMessageList);
161+
if (!messageStreamController.isClosed) {
162+
messageStreamController.sink.add(initialMessageList);
163+
}
155164
}
156165

157166
/// Function for getting ChatUser object from user id

0 commit comments

Comments
 (0)