marcglasberg / async_redux

Flutter Package: A Redux version tailored for Flutter, which is easy to learn, to use, to test, and has no boilerplate. Allows for both sync and async reducers.
Other
230 stars 41 forks source link

Best way to handle nested navigation flows? #118

Closed pitazzo closed 2 years ago

pitazzo commented 2 years ago

In some projects, handling all routes from a top level navigator is too complex and leads to a unmaintainable routing method. In those cases, the official Flutter docs propose using nested navigators. However, I'm not totally confident about how this approach can be used while also using the navigation features of this plugin, as it relies on setting a unique key for each navigator, which does not seem to be compatible to the setting of the navigator key (NavigateAction.setNavigatorKey(navigatorKey)).

Thus, I wonder which is the best practice for handling complex (nested flows) routes while using this package.

marcglasberg commented 2 years ago

The navigation capabilities of AsyncRedux are just convenience methods that help you think of navigation as just another action to dispatch. But you don't really need to use it at all. You can just ignore everything that AsyncRedux offers in terms of navigation and do it in your own way. In that case, AsyncRedux won't help you, but it also won't make it any harder for you.

In other words, If your app has a simple navigation, and Navigator 1.0 is your choice, I do recommend you use AsyncRedux's navigation capabilities. However, when using nested navigators in Navigator 1.0 it won't work. Also, nowadays there is Navigator 2.0, and a lot of different packages to simplify navigation with it, and AsyncRedux couldn't possibly work with all of them.

My suggestion is that you do your navigation inside of your action's reducers, by calling your navigation methods there.