Lee Probert
Lee Probert

Reputation: 10859

Flutter subclass Scaffold so I can ensure a Drawer and BottomNavigationBar are always present

I have a Flutter app with sections that I can access from both a BottomNavigationBar and a Drawer. I have this working in a Scaffold at the root level of my app, and I then use Navigator widgets to create separate routes and stacks within each section. The BottomNavigationBar persists as I push new screens onto the stack, and these new screens will have their own AppBar and actions specific to those user journeys.

The problem is that I need the Drawer to be present on all of my screens, and setting a new AppBar in a Scaffold on individual screens removes the Drawer that I had set in my root level Scaffold.

How can I pass that Drawer through to all my screen AppBar instances? I don't want to create new Drawer instances over multiple widgets, so I should create a Singleton of the Drawer or even the entire Scaffold? What's the best practise here?

Upvotes: 0

Views: 185

Answers (1)

ahmed
ahmed

Reputation: 454

You can use a state management package. I suggest use provider packages or flutter_bloc so that you can get more out of flutter UI but be careful about their name and here is a doc link that is made by flutter team and will help you with all the state management package: https://flutter.dev/docs/development/data-and-backend/state-mgmt/options

This one is for bloc_flutter doc I couldn't find it on the previous link document: https://bloclibrary.dev

Upvotes: 0

Related Questions