Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
Application state is set outside of the Redux Store, specifically navigation route #15
Is there a practical method to add route/navigation to the Redux AppState? In the redux example of this repo, DetailsScreen in detail_screen.dart and HomeScreen in home_screen.dart, both presentations components, are setting the state of the app via the Navigator. I am trying to figure out a way to include the route in the AppState and then implement subsequent routes outside presentation components, possibly through Middleware. I have failed thus far. :(
Much like the app presents the active tab via the store, I think the app should present the route via the store. Is this reasonable?
BTW - thanks so very much for this repo, it has been a great help to me getting off the ground with Flutter, Redux, and Dart.
This is a good question, and something I've thought a bit about as well. These are only my ideas, so would be happy to hear yours in response!
First of all, I wouldn't worry about putting absolutely everything into your Redux store, and I believe the Navigator is one of those cases. Why? Because the Navigator handles a lot of things: back button support, animations between screens, showing back arrows in the App Bar, deep linking, etc, and I generally don't think these things should be the responsibility of the Redux Store.
See also this series of tweets from the original Redux author: https://twitter.com/dan_abramov/status/727278247264833536?lang=en
Therefore, I think the best way to pass data between routes is actually through named routes with query parameters. My main reason: To handle all Routes in the same way, especially deep links, which are really important to handle gracefully.
The only problem I have with using named routes at this time: handling query params in routes with Flutter is a bit clunky at the moment. You need to write your own
For example, in the Redux example, I think I should refactor this bit:
That way, even if someone links to your app from another app, they could link to
If you still want to sync the Router with the Store, I think you could totally do it!
So, that's a lot of writing haha, whatcha think overall?
Thank you @brianegan for your words and your time. I was concerned about including the routes in the store, as I was not sure if the navigation would work as well, but I also am interested in giving it a try, which is why I asked my question.
Thanks again and I will keep you updated on what I learn. Cheers!
@kinggolf Sure thing! Would love to hear what ya learn. Ya, definitely only bring in Redux patterns when you feel they're necessary.
To make Redux work a bit more like ngrx with "effects," you can check out the
Also, I haven't written much about it or put as much time into documentation / flutter integrations, but if you like the full