0

I want to display a sidebar to the right of the entire Scaffold, such that when the user navigates between routes in the Scaffold, for example using Navigator.of(context).pushNamed(), the sidebar should be unaffected. In the sidebar, I also need to have a button that displays widgets in front of the entire Scaffold.

It seems simple enough to just use the MaterialApp's builder-method to surround the entire app with a Row and possibly a Stack (to be able to display things in front of the Scaffold). The problem is that there seem to be a few puzzle pieces missing when using the builder method, for example Overlay and Material. If I add them manually, it seems to work.

builder: (context, child) {
  return Overlay(
    initialEntries: [
      OverlayEntry(builder: (context){
        return Row(
          children: [
            Expanded(child: child),
            Material(child: MySideBar()),
          ],
        );
      })
    ],
  );
},

Is this a good way to structure this kind of app? It honestly feels kind of sketchy. Is there a better approach, or even an official way to do it?

Magnus
  • 17,157
  • 19
  • 104
  • 189
  • Does the NavigationRail widget not serve your needs for a persistent sidebar? https://api.flutter.dev/flutter/material/NavigationRail-class.html – CStark Aug 24 '23 at 13:47
  • @CStark No, and even if it did it doesn't answer the question of what the preferred solution would be to place it outside the `Scaffold`. I'm not asking about how to make a sidebar, I'm asking about the best way to place it outside the `Scaffold` and still have full and reliable functionality of the app. – Magnus Aug 24 '23 at 19:07

0 Answers0