New post on /r/flutterdev subreddit:
<b>What are your thoughts on Navigator 2.0? (And Flutter navigation in general?)</b>
I'm a React Native developer who's been learning flutter for about a week or so and I've got to say that I really love it. For the most part, it seems to do <strong>everything</strong> better than RN, and the static typing and structured widget arguments is soooo much nicer than JSX.That said, one area which I'm not so sure about is the navigation. In React Native, React-Navigation explicitly has multiple types of navigators (Stack, Tab, Drawer, Switch etc) and allows nesting them whilst also being able to call any navigator (without even having to specify which one, provided screen name are unique) within the stack from any screen/component. However, looking at Flutter's built-in Navigator I'm somewhat baffled by its design.Navigator 1.0Having <code>push</code>, <code>pop</code> seems to be a good start, but there's still essentially only one big stack, with limited ways of manipulating the stack (e.g. not being able to pop one below, clear entire stack except current).Navigator 2.0An explicit Navigator widget seems to be a good step in the right direction in my opinion, so that you can have multiple independent or nested navigators depending on which part of the app you're in. That said, I'm not entirely keen on the how the pages argument of the Navigator is used. From <a href="
https://medium.com/flutter/learning-flutters-new-navigation-and-routing-system-7c9068155ade">this tutorial</a> I gather that you should have some sort of condition in your pages argument which checks if there should be a certain page a la <code>[ RootPage(), if (_book != null) BookPage(book) ]</code> but this seems terribly constricting due to the fact that now if I want to add another route for movies it would then be <code>[ RootPage(), if (_book != null) BookPage(book), if (_movie != null) MoviePage(movie) ]</code> , which means I can't have the following stack <code>[ Root, Movie, Book ]</code>. Or more importantly I can't have a stack of multiple different books (e.g. navigating through recommendations).The only way I can see to remedy this would then to have pages as <code>[ RootPage() ]</code>, then use the 1.0 navigator api to <code>push</code> and <code>pop</code> normally. That said, whilst I'm aware the 1.0 and 2.0 APIs can be used in conjunction I've yet to see any actual guides or documentation showing this case. One such scenario that isn't clear on is if I call <code>Navigator.push(AnotherRoute())</code> whilst I'm on <code>[ RootPage() ]</code>, what happens if within that new page I call a <code>setState</code> on that <code>_book</code>? Will my stack be <code>[ RootPage(), AnotherRoute(), BookPage() ]</code>, or <code>[ RootPage(), BookPage(), AnotherRoute() ]</code>?Named RoutesAnother aspect I'm not terribly fond of is the route naming convention (and the behaviour that it implies). There seems to be a very large effort in making navigation compatible with web URLs, but I'm baffled as to why this is the case when native application navigation and web URL navigation are fundamentally so different. For example, when I push the routes <code>Book</code>, <code>Movie</code>, <code>Book</code>, <code>Movie</code> in that order, is my URL now at <code>/book/movie/book/movie</code>? On the web, URL and history stack are two completely separate things yet I think I've skimmed over a good amount of documentation about how to parse this into a stack. Admittedly I haven't gone over the web/URL functionality much and could be entirely wrong about this, I just think its a strange route naming convention.The bigger problem I see is that named routes and are passed into <code>MaterialApp</code>, and not <code>Navigator</code>. Therefore I don't see how it's possible to use named routes in nested navigators (e.g. bottom tabs). In React-Navigation each navigator could register a number of screens, and doing <code>navigator.nav…