From dd6b0c09029f3f5bc0af64f4fb94ef1517b660b0 Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Thu, 22 Dec 2022 15:38:35 +0300 Subject: [PATCH] Scroll to Message --- lib/provider/chat_provider_model.dart | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 7ffc0e7..40e9327 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -1320,21 +1320,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void scrollToMsg(SingleUserChatModel data) { if (data.userChatReplyResponse != null && data.userChatReplyResponse!.userChatHistoryId != null) { int index = userChatHistory.indexWhere((SingleUserChatModel element) => element.userChatHistoryId == data.userChatReplyResponse!.userChatHistoryId); - double contentSize = scrollController.position.viewportDimension + scrollController.position.maxScrollExtent; - double target = contentSize * index / userChatHistory.length; - scrollController.position.animateTo( - target, - duration: const Duration(seconds: 1), - curve: Curves.easeInOut, - ); - - // scrollController.scrollTo(index: 150, duration: Duration(seconds: 1)); - // scrollController.animateTo(offset, duration: duration, curve: curve); + if (index >= 1) { + double contentSize = scrollController.position.viewportDimension + scrollController.position.maxScrollExtent; + double target = contentSize * index / userChatHistory.length; + scrollController.position.animateTo( + target, + duration: const Duration(seconds: 1), + curve: Curves.easeInOut, + ); + } } - // scrollController.animateTo( - // scrollController.position.maxScrollExtent, - // duration: const Duration(milliseconds: 100), - // curve: Curves.easeOut, - // ); } }