Best way to display widgets outside of the main Scaffold?

37 Views Asked by At

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?

0

There are 0 best solutions below