From c9439b6a7b12288d14c71c404f2d5a8cfb95b4a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonas=20Badst=C3=BCbner?= Date: Tue, 11 Jun 2024 09:29:57 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20prevent=20actions=20if=20?= =?UTF-8?q?receiver=20is=20not=20capable=20of=20dealing=20with=20them?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CHANGELOG.md | 2 ++ lib/src/controller/chat_controller.dart | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf68460c..7a3f45b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,8 @@ send message not working when user start texting after newLine. * **Fix**: [191](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/191) Fix error when using `BuildContext` or `State` extensions when not mounted. +* **Fix**: [192](https://github.com/SimformSolutionsPvtLtd/flutter_chatview/pull/192) Fix + send to closed socket or animate on `ScrollController` without clients. ## [1.3.1] diff --git a/lib/src/controller/chat_controller.dart b/lib/src/controller/chat_controller.dart index b1649911..2a5b148f 100644 --- a/lib/src/controller/chat_controller.dart +++ b/lib/src/controller/chat_controller.dart @@ -89,7 +89,9 @@ class ChatController { /// Used to add message in message list. void addMessage(Message message) { initialMessageList.add(message); - messageStreamController.sink.add(initialMessageList); + if (!messageStreamController.isClosed) { + messageStreamController.sink.add(initialMessageList); + } } /// Used to add reply suggestions. @@ -134,24 +136,31 @@ class ChatController { messageType: message.messageType, status: message.status, ); - messageStreamController.sink.add(initialMessageList); + if (!messageStreamController.isClosed) { + messageStreamController.sink.add(initialMessageList); + } } /// Function to scroll to last messages in chat view void scrollToLastMessage() => Timer( const Duration(milliseconds: 300), - () => scrollController.animateTo( - scrollController.position.minScrollExtent, - curve: Curves.easeIn, - duration: const Duration(milliseconds: 300), - ), + () { + if (!scrollController.hasClients) return; + scrollController.animateTo( + scrollController.position.minScrollExtent, + curve: Curves.easeIn, + duration: const Duration(milliseconds: 300), + ); + }, ); /// Function for loading data while pagination. void loadMoreData(List messageList) { /// Here, we have passed 0 index as we need to add data before first data initialMessageList.insertAll(0, messageList); - messageStreamController.sink.add(initialMessageList); + if (!messageStreamController.isClosed) { + messageStreamController.sink.add(initialMessageList); + } } /// Function for getting ChatUser object from user id