scrollToLastVisibleChild method

Future<void> scrollToLastVisibleChild(
  1. INode parent
)

Implementation

Future<void> scrollToLastVisibleChild(INode parent) async {
  final lastChild = parent.childrenAsList.lastOrNull;
  if (lastChild == null) return;

  await Future.delayed(animationDuration);

  //get the index of the last child in the node
  final lastChildIndex = animatedListStateController.indexOf(lastChild);

  //scroll to the last child if it is not visible in the viewPort
  if (!scrollController.isIndexStateInLayoutRange(lastChildIndex +
      parent.level.clamp(1, 1000) +
      parent.childrenAsList.length)) {
    await scrollController.scrollToIndex(
        lastChildIndex < animatedListStateController.list.length - 1
            ? lastChildIndex + 1
            : lastChildIndex,
        preferPosition: AutoScrollPosition.end);
  }
}