Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter how can i hide bottomnavbar in specific screens?

I have a bottom navbar but in some pages i want to hide it. How can i make it ? For example i want to see appbar in HomeScreen but i dont want see it on search screen. My code is like :

Scaffold(
      backgroundColor: _selectedIndex == 0 ? Colors.transparent : Colors.white,
      extendBodyBehindAppBar: _selectedIndex == 0 ? true : false,
      bottomNavigationBar: _navBarItems,
      body: Navigator(
        onGenerateRoute: (settings) {
          Widget page = const HomeScreen();
          if (settings.name == '/help_center') {
            page = const HelpCenterScreen();
          } else if (settings.name == '/search') {
            page = const SearchScreen();
          }
          return MaterialPageRoute(builder: (_) => page);
        },
      ),
    );

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Simple wrap _navBarItems with Visibility widget:

//class variable
bool _isVisible = true;//default true

Scaffold(
  backgroundColor: _selectedIndex == 0 ? Colors.transparent : Colors.white,
  extendBodyBehindAppBar: _selectedIndex == 0 ? true : false,
  bottomNavigationBar: Visibility(
       visible: _isVisible,
       child: _navBarItems,
  ),
  body: Navigator(
    onGenerateRoute: (settings) {
      Widget page = const HomeScreen();
      if (settings.name == '/help_center') {
        page = const HelpCenterScreen();
        setState(() {
           _isVisible = true;
        });
      } else if (settings.name == '/search') {
        setState(() {
           _isVisible = false;
        });
        page = const SearchScreen();
      }
      return MaterialPageRoute(builder: (_) => page);
    },
  ),
);

And change visibility in if else structure with setState method.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading