navigate method

void navigate({
  1. int? pageIndex,
  2. int? tabIndex,
})

Navigates to the specified page and tab indices.

If pageIndex is not provided, the current page index is used. If tabIndex is not provided and pageIndex is different from the current page index, the tab index is set to 0. Otherwise, the current tab index is used.

If either pageIndex or tabIndex is different from the current indices, the previous indices are stored in the history list, and the current indices are updated. Additionally, a log message is printed to the console indicating the navigation change.

Implementation

void navigate({int? pageIndex, int? tabIndex}) {
  if (pageCount == 0) return;
  pageIndex ??= this.pageIndex;

  // if page index is higher than the page count, round navigate to index 0 + the difference
  if (pageIndex >= pageCount) {
    pageIndex = 0 + (pageIndex - pageCount);
  }

  if (pageIndex != this.pageIndex && tabIndex == null) {
    tabIndex = 0;
  } else {
    tabIndex ??= this.tabIndex;
  }

  if (pageIndex != this.pageIndex || tabIndex != this.tabIndex) {
    consoleLog("From $previousPageIndex:$previousTabIndex to $pageIndex:$tabIndex");
    _pageIndex = pageIndex;
    if (currentPage.hasTabs) {
      // if page index is higher than the tab count, round navigate to index 0 + the difference
      if (tabIndex >= currentPage.tabs.length) {
        tabIndex = 0 + (tabIndex - currentPage.tabs.length);
        currentPage.tabController?.animateTo(tabIndex);
      }
    } else {
      tabIndex = 0;
    }
    _tabIndex = tabIndex;
    insertHistory(pageIndex, tabIndex);
    notifyListeners();
  }
}