animateToBottom method

Future<void> animateToBottom()

Animates listController to the last _history, if any, or the last ChatItem in the RxChat.messages otherwise.

Implementation

Future<void> animateToBottom() async {
  if (_history.isNotEmpty) {
    final ChatItem item = _history.removeLast();
    await animateTo(item.id, item: item, addToHistory: false);
    _updateFabStates();
  } else if (chat?.messages.isEmpty == false && listController.hasClients) {
    if (chat?.hasNext.value != false) {
      if (chat?.lastItem != null) {
        return animateTo(chat!.lastItem!.id, item: chat!.lastItem);
      }
    }

    canGoDown.value = false;

    _itemToReturnTo = _topVisibleItem;

    try {
      _ignorePositionChanges = true;
      await listController.sliverController.animateToIndex(
        0,
        offset: 0,
        offsetBasedOnBottom: false,
        duration: 300.milliseconds,
        curve: Curves.ease,
      );
      canGoBack.value = _itemToReturnTo != null;
    } finally {
      _ignorePositionChanges = false;
    }
  }
}