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
389 stars 63 forks source link

[Feature Request] `FlowController<T>` should implement `ValueListenable<T>` instead of `Listenable` #66

Closed narcodico closed 2 years ago

narcodico commented 2 years ago

Is your feature request related to a problem? Please describe. Currently flow_builder can't be used to build widgets. Although flow_builder's responsibility is building the navigation stack, users could also benefit from being able to use ValueListenableBuilder with a FlowController.

Describe the solution you'd like FlowController<T> should implement ValueListenable<T> instead of Listenable. The only downside is this would force FlowController to override ValueListenable's value. Right now the value's role is played by the state property. Couple of options to overcome this:

If you like this change I'm willing to open a PR.

Gene-Dana commented 2 years ago

@narcodico Will this change allow us to pass a List<Widget as opposed to a List<Pages> with onGeneratePages?

narcodico commented 2 years ago

@narcodico Will this change allow us to pass a List<Widget as opposed to a List<Pages> with onGeneratePages?

No. But you could potentially use ValueListenableBuilder similar to BlocBuilder to build different widgets, but that kinda goes against the whole concept of flow builder, since when you're creating one you'll specify the onGeneratePages which will determine the stack of pages by using the current flow state.

This change would be beneficial when needing to build some UI based on the flow state/part of it. This change could potentially eliminate a lot of scenarios where you make the flow depend on a bloc's state simply because you need to build UI while also being able to drive a flow.

felangel commented 2 years ago

@narcodico thanks for opening an issue!

There have been some recent changes to refactor FlowController to extend ChangeNotifier rather than to implement Listenable (see #61). As a result, you should be able to use an AnimatedBuilder with the FlowController to rebuild some UI based on the state (available in flow_builder v0.0.5).

Let me know what you think, thanks!

narcodico commented 2 years ago

@felangel that will also do the job! 👍

felangel commented 2 years ago

Awesome, closing for now but let me know if you have any additional feedback/suggestions and I'm happy to reopen this 👍