1

In my app I have a BottomBar that handles my Pages. Right now I am simply handling it with Callbacks like this:

return Scaffold(
            body: PageView(
                controller: tabController,
                children: <Widget>[
                  HomeScreen(),
                  MultiProvider(
                    providers: [
                      ChangeNotifierProvider(
                        create: (context) => ScannerModel(),
                      ),
                      ChangeNotifierProvider(
                        create: (context) => ArticleSearchModel(),
                      ),
                    ],
                    child: ScanPage(),
                  ),
                  SettingsScreen(
                    packageInfo: _packageInfo,
                  ),
                ],
                physics: NeverScrollableScrollPhysics(),
                onPageChanged: (index) => setPageColor(index, context),
              ),
            ),
            bottomNavigationBar: FABBottomAppBar(
              items: [
                FABBottomAppBarItem(
                    iconUrl: 'images/bottom_bar_icons/home.svg'),
                FABBottomAppBarItem(
                    iconUrl: 'images/bottom_bar_icons/search.svg'),
                FABBottomAppBarItem(
                    iconUrl: 'images/bottom_bar_icons/settings.svg'),
              ],
              onPageChanged: (index) {
                
                tabController.jumpToPage(index); // <- change page
              },
          );
        } 

So far so good, it is working perfectly fine.

Problem:

The user can also get to another page by clicking a button that is nested quite deep inside the widget-tree. Now, I know I could use a ton of callbacks and pass the info right to the top. But that would require at least 5 callbacks and that seems rather ugly.

So: How can I change the tabControllers page from anywhere in a simple way?

Let me know if you need any more info!

Chris
  • 1,828
  • 6
  • 40
  • 108

0 Answers0