-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No support for nested Navigators? #23
Comments
This is not difficult to implement, I would do it in a few minutes, but my concern is that it can have side effects, and major performance problems. |
Do you think these are really practical concerns though? Dart is very fast, Flutter has low memory usage in general, is also very quick at inflating/deflating widgets. I think this case of many navigators, with many pages all stacked up, is quite outside the main path of like 1 root navigator, and 1 or 2 sub navigators that I keep running into anytime I want to have some persistent chrome around my content pages. Without this, I wonder how you would recommend doing anything like this currently? I'm thinking desktop apps specifically, where this sort of persistent menu/nav bar is always present: Also, as I understand page routes, unless you set them to be non-opaque, the widgets are removed, and the page route deflated, as soon as the new route has finished transitioning in. |
If there is no abuse, as in your case, there would be no problems. If you want to see in practice how this happens, reproduce the example below and you will see that when pushing a new route, all the others below the opaque route are rebuild. import 'package:flutter/material.dart';
void main() {
runApp(new MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return new MaterialApp(
title: 'Flutter Demo',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new MyHomePage(id: 1),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.id}) : super(key: key);
final int id;
@override
_MyHomePageState createState() => new _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
print('Page ${widget.id} built!');
return new Scaffold(
appBar: new AppBar(
title: new Text(widget.id.toString()),
),
body: new Center(
child: new RaisedButton(
child: new Text('Open next page'),
onPressed: () {
Navigator.of(context).push(
new MaterialPageRoute(
builder: (_) => new MyHomePage(id: widget.id + 1),
maintainState: true
)
);
}
)
),
);
}
} The widgets are not removed, they remain in memory, the only thing that changes is that the app will be bottlenecked by a setState in the entire materialApp. Here is an example of the memory usage between Get with opaque = false and MaterialPageRoute with opaque = true: However, goderbauer is solving this already. He did a recent pull on the master that took the GlobalKey from the overlay off the stage, preventing a new one from being created with each navigation, but this was reversed 2 days later because it caused instability in the snackbar, which needs a new GlobalKey to stack a OverlayRoute over the normal route. Numerous changes were made, which even caused this lib to be incompatible with the master, so I stopped following until the changes went to Dev. |
Wow, good to know! Thx for the overview. |
I supposed this is the place to be for the nested navigators that you mentioned on the other ticket. Looking forward to it! |
Added on branch dev 1.19.0-dev. |
Just curious how you see this working in apps where I have multiple views containing tab bars, or a desktop style app that has sidemenu that pushes views to the content area in the right, but still wants to show fullscreen dialogs over the entire app.
Seems like this would be more flexible if it had the ability to have the root navigator, but also a context based lookup.
The text was updated successfully, but these errors were encountered: