initPageControllers method

void initPageControllers()

Implementation

void initPageControllers() {
  _appBarPageController = PageController(initialPage: controller.currentTab?.index ?? 0);
  _bodyPageController = PageController(initialPage: controller.currentTab?.index ?? 0);

  _appBarPageController.addListener(() {
    // syncing body PageView with header PageView
    if (_bodyPageController.hasClients) {
      _bodyPageController.position.correctPixels(_appBarPageController.offset);
      _bodyPageController.position.notifyListeners();
    }

    // syncing controller's current page after header swipe gesture
    if (_appBarPageController.hasClients &&
        _appBarPageController.page == _appBarPageController.page!.floorToDouble() &&
        !_isNavigatingToPage) {
      var index = _appBarPageController.page!.floor();
      if (controller.currentTab != null && controller.currentTab!.index != index) {
        controller.switchToTab(index);
      }
    }
  });
}