5

Coming from a web background (angular), I'm really confused about flutter routing.

It seems like I'm not alone (1, 2, ...).

Judging by the relative complexity of the answers and the various bugs associated with some of them, I'm wondering if I'm just trying to use the navigator as something it is not. I'm trying to use it like I would use a router of a web framework. If the routing in flutter is intended to change a whole screen and not children widgets.

web_nav

On the Web the following navigation would be something like this:

{ path: '/sign-in', widget: SignInPage() },
{ path: '/', widget: HomePage(), children: [
    { path: '/a', widget: DashboardPage() },
    { path: '/b', widget: ProfilePage(), children: [
       { path: '/general', widget: BGeneralPage() },
       { path: '/settings', widget: BSettingsPage() },
    ] }
] }
// example url x.com/b/settings

In flutter you can put a nested Navigator, but the hot reloading seem to fail, also the default animation is quite junky. Even the documentation on nested navigation says << a similar result is possible using only a single Navigator >>.

It looks to me like that the routing system is intended to be used when we want to change the whole screen. PageView and TabBarView are the widgets to use for inner navigation.

- Is it the case ?

However, I see a potential problem with that when flutter web will be available it won't have matching urls.

Ced
  • 15,847
  • 14
  • 87
  • 146
  • Navigator 2 docs indicate some possibilities to implement your own router with uri parsing and onRouteGenerate. Have you looked into additionnal packages to handle routing in an angular-like way (like GetX) ? – Vincent AUDIBERT May 08 '21 at 07:44
  • flutter_modular (instead of GetX) filled some similar needs in my case in the end, bringing an angular-like way to declare modules and their nested routing. – Vincent AUDIBERT May 12 '21 at 14:10
  • I try with auto route nested navigation. any better solution. I want to have shared layout template . in angular we just past router outlet. – Sras May 18 '22 at 13:49

0 Answers0