slovnicki / beamer

A routing package built on top of Router and Navigator's pages API, supporting arbitrary nested navigation, guards and more.
MIT License
591 stars 129 forks source link

Unable to hide Bottom Navigation on certain routes #611

Closed mattsrobot closed 1 year ago

mattsrobot commented 1 year ago

Describe the bug I have a Cupertino App using the Tab Bar (bottom navigation equivalent).

Certain routes require the tab bar to be hidden.

There doesn't appear to be a way to hide the tab bar. With the Navigator API, this would be equivalent of setting rootNavigation: true to hide the tab bar.

I don't see a way to do it with Beamer :-(

STRENCH0 commented 1 year ago

I made this. It hides the tab bar on non-root pages. And you can actually do different strategies for different locations using this solution.

  Widget build(BuildContext context) {
    var location = _beamerDelegate.currentBeamLocation;
    _isVisible = location.state.uri.pathSegments.length <= 1;
    if (location is YourLocation) {
      _currentIndex = 0;
    } else if (location is YourAnotherLocation) {
      _currentIndex = 1;
    }
    return Visibility(
     visible: _isVisible,
     child: NavigationBar(
       ...
     )
  }
jasonlessenich commented 1 year ago

This just seems wrong tho - Is there a "better" solution for this?

slovnicki commented 1 year ago

Hey @mattsrobot :wave: Thanks for creating an issue and sorry for my absence lately.

I believe you are looking for the behavior demonstrated in bottom_navigation_2 example, as opposed to bottom_navigation_multiple_beamers example where the routes are within nested Beamers.

It's all about structuring the routes and Beamers (i.e. Routers, i.e. Navigators) that handle them. And yes, it is exaclty like using rootNavigator: true. Once the parent (most often root) Beamer is setup to handle that route you wish to show above the nested tab routers, you can call Beamer.of(context, root: true).beamTo... to show that page.

The solution proposed by @STRENCH0 is surely valid for use cases when you want exactly that behavior, but the above mentioned examples answer the question from the perspective of Navigator hierarchy.

mattsrobot commented 1 year ago

Hey @slovnicki @STRENCH0

Much appreciated, I'm going to try using your solutions, very thankful for the responses given.

Cheers

Matt