loadNextChatHistory method

void loadNextChatHistory()

Implementation

void loadNextChatHistory() {
  final itemPositions = newitemPositionsListener.itemPositions.value;

  if (itemPositions.isNotEmpty) {
    final firstVisibleItemIndex = itemPositions.first.index;

    debugPrint("reached length ${itemPositions.first.itemLeadingEdge}");
    debugPrint("reached firstItemIndex $firstVisibleItemIndex");
    debugPrint("reached chatList.length ${chatList.length}");
    debugPrint("reached itemPositions.length ${itemPositions.length}");

    if (Platform.isIOS) {
      ///This is the top constraint changing to bottom constraint and calling nextMessages bcz reversing the list view in display
      if (firstVisibleItemIndex <= 1 &&
          double.parse(
                  itemPositions.first.itemLeadingEdge.toStringAsFixed(1)) <=
              0) {
        // Scrolled to the Bottom
        debugPrint("reached Bottom yes load next messages");
        _loadNextMessages();

        ///This is the bottom constraint changing to Top constraint and calling prevMessages bcz reversing the list view in display
      } else if (firstVisibleItemIndex + itemPositions.length >=
          chatList.length) {
        // Scrolled to the Top
        _loadPreviousMessages();
        debugPrint("reached Top yes load previous msgs");
      }
    } else if (Platform.isAndroid) {
      if (firstVisibleItemIndex == 0) {
        debugPrint("reached Bottom yes load next messages");
        _loadNextMessages();
      } else if (firstVisibleItemIndex + itemPositions.length >=
          chatList.length) {
        debugPrint("reached Top yes load previous msgs");
        _loadPreviousMessages();
      }
    }
  }
}