// There is no other way to scroll to the end of a lazy listView and
// unknown height for each widget (the height is not fixed) in the list.
// If you know the height for each widget or the height is fixed
// DO NOT use this code!
Future<void> _scrollToLatestMessage() async {
await Future.delayed(const Duration(milliseconds: 50));
if (chatScrollController.position.pixels <
chatScrollController.position.maxScrollExtent) {
await chatScrollController.animateTo(
chatScrollController.position.maxScrollExtent,
duration: const Duration(milliseconds: 250),
curve: Curves.easeInCubic,
);
await _scrollToLatestMessage();
}
}