canNavigate method

bool canNavigate(
  1. bool swipeLeft
)

Implementation

bool canNavigate(bool swipeLeft) {
  if (appState.document == null) return false;
  final totalPages = appState.document!.pagesCount;
  final currentPageIndex = appState.currentPage * 2;

  if (swipeLeft) {
    if (totalPages % 2 == 0) {
      /// Even number of pages: allow if currentPageIndex < totalPages - 2 or at the last spread
      return currentPageIndex < (totalPages - 2) ||
          currentPageIndex == (totalPages - 2);
    } else {
      /// Odd number of pages: allow if currentPageIndex < totalPages - 1
      return currentPageIndex < (totalPages - 1);
    }
  } else {
    /// Can't go backward if at first page
    return appState.currentPage > 0;
  }
}