felangel / flow_builder

Flutter Flows made easy! A Flutter package which simplifies navigation flows with a flexible, declarative API.
https://pub.dev/packages/flow_builder
MIT License
395 stars 65 forks source link

Multiple flow_builder in an app #53

Closed utipe closed 3 years ago

utipe commented 3 years ago

I just started learning how to use this (very useful) package and have a question relating to its usage: Suppose my app has multiple flows e.g. authentication flow then profile flow etc., how should I handle combining these flows together? Should I just add the profile flow on top of the authentication flow?

Thank you!

omartinma commented 3 years ago

Maybe it helps, but i just had a similar case and in your case, if profile page is one of the "states" in your authentication flow then you will have a ProfilePage and this one will return a new FlowBuilder that will have X state. Hope it helps!

nghetien commented 3 years ago

I am a newbie and I just had a similar case:

  1. flow_builder for state authentication (Widget parent)
    • If authenticated to Homepage
    • If unauthenticated to LoginPage
  2. flow_builder for routes (Widget children)
    • use it to go to other page when authenticated

So what is the best way for this case?

Thank you!

omartinma commented 3 years ago

Maybe @felangel can correct me, but in your case I would have one top level FlowBuilder as you mentioned just checking the authentication. If authenticated you will have your HomePageRouter or something similar that will guide to every of your features. Usually what i do is define some steps(could be an enum, or could be a model) and depends of the route i will change that model/enum so your HomePageRoutter can handle the different routes. If the authentication state changes, as you have a FlowBuilder on top of that, no matter what will have "preference" and will route to login page if needed.

felangel commented 3 years ago

Hi @utipe 👋 Thanks for opening an issue!

As @omartinma mentioned, I'd recommend having a single FlowBuilder that reacts to changes in the Authentication State and you can have nested FlowBuilders for subsequent flows. I don't recommend combining them into a single flow as that will get bloated and become difficult to test/maintain. Hope that helps 👍

utipe commented 3 years ago

Thank you for all your comments! That definitely helps me a lot! I guess I can close this issue for now.