Fragment-like behavior in Flutter

1,267 views
Skip to first unread message

Federico Magnani

unread,
Nov 24, 2017, 10:10:20 AM11/24/17
to Flutter Dev
Hi, I'm making a Flutter app with a drawer.
I would like the drawer to be the same for every route/page in the app, but every time i push a new page, the whole thing is being replaced, and I lose the drawer.

Now, I could make it singleton, I could just be creative and build a different widget as the content of the page, but it just doesn't feel the right thing to do.
What I need is a behavior like the Fragments on Android, where I can push the new page inside a container, and the rest of the layout remain untouched.

Thanks for the great work!
(And sorry for my english)

Collin Jackson

unread,
Nov 28, 2017, 3:09:53 PM11/28/17
to Federico Magnani, Flutter Dev
You might want to try making the Scaffold a parent of the Navigator, as in this example. Then you can push new routes onto the history stack without replacing the drawer.

--
You received this message because you are subscribed to the Google Groups "Flutter Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Peter King

unread,
May 19, 2018, 1:34:26 PM5/19/18
to Flutter Dev
This will work, but still isn't ideal, doesn't feel right, it's not the same as gmail or inbox etc. by creating a new Navigator is all well and good, but it only goes half way in getting the right user flow.
What is missing from you suggestion is the Back button doesn't return back to where it came from... How can this be achieved?

OR should one even be doing this, every item from the drawer, should it always show the screen with a back arrow? This works perfectly out of the box.
Is Google not following material properly by having the drawer available when an item is clicked, if not, how do we get the same functionality without writing loads of code in Flutter?

It would be nice to attached a new property to the Drawer or AppBar, whereby in ones new Page it will infer the UI from the previous widget perhaps...

A quick way around this is to share the Drawer object entirely I guess... is this a good idea or practical?
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages