1

I have an app with a bottom bar that is used to navigate between the three main tabs of the app using AutoTabsRouter.pageView(). The bottom bar is only visible in some parts of the app, so I need a function that controls its animation. Also depending on the bottom bar being visible or not, the physics of the AutoTabsRouter.pageView() changes between swipable and not. Since each page of the app is pretty complicated, I defined the following listenable:

class BottomBarModel extends ChangeNotifier {
  BottomBarModel(this.animationController);

  AnimationController animationController;
  bool isVisible = true;

  void toggleBar({required bool visibility}) {
    if (isVisible == visibility) {
      return;
    }
    if (visibility) {
      animationController.reverse();
    } else {
      animationController.forward();
    }
    isVisible = visibility
    notifyListeners();
  }
}

This way, I initialize the BottomBar using ChangeNotifierProvider, which sits just above the pageView, and access it anywhere in the app. It looks something like:

ChangeNotifierProvider(
      create: (context) => BottomBarModel(animationController),
      child: AutoTabsRouter.pageView(
        physics: ???
            ? const ClampingScrollPhysics()
            : const NeverScrollableScrollPhysics(),
        routes: const [Section1(), Section2(), Section3()],
        builder: (context, very_expnesive_widget, _) {
          return Scaffold(
            bottomNavigationBar: BottomBar(),
            body: very_expnesive_widget,
          );
        },
      ),
    );

The problem is how do I change the physics of the pageView without rebuilding its very expensive children?

0 Answers0