scrollToBottom method

Future<void> scrollToBottom()

The method for the scroll to bottom.

Implementation

Future<void> scrollToBottom() async {
  if (controller.hasClients) {
    Logger().i(
        '[easy-chat-scroll-controller] scrollToBottom check offset: ${controller.offset}, maxScrollExtent: ${controller.position.maxScrollExtent}');
    while (controller.offset + 1 < controller.position.maxScrollExtent) {
      Logger().i(
          '[easy-chat-scroll-controller] scrollToBottom offset: ${controller.offset}, maxScrollExtent: ${controller.position.maxScrollExtent}');
      controller.animateTo(
        controller.position.maxScrollExtent,
        duration: Duration(milliseconds: animationDurationInMilliseconds),
        curve: Curves.easeOut,
      );
      await Future.delayed(
        Duration(milliseconds: animationDurationInMilliseconds),
      );
    }
  }
}