flutter-form-builder-ecosystem / flutter_form_builder

Simple form maker for Flutter Framework
https://pub.dev/packages/flutter_form_builder
MIT License
1.49k stars 537 forks source link

Provide Streams for FormBuilderState #1155

Open erayerdin opened 1 year ago

erayerdin commented 1 year ago

Environment

Package version: 7.7.0

Description

What you'd like to happen:

For example, the package connectivity_plus has a onConnectivityChange stream. When you subscribe to it, you get the changes in real time.

_formKey.currentState!.onChange.listen((Map<String, FormBuilderFieldState<FormBuilderField, dynamic>> values) {
  // do what you want to do with fields
});

This is especially useful in state managers, specifically Bloc. Here, from Flutterly's Bloc tutorial from 8:34, you can see how streams can be utilized in Bloc.

deandreamatias commented 1 year ago

This will be a nice feature. Things to consider:

erayerdin commented 1 year ago

This onChange should be apply only entire form, for single fields or for both?

I think the entire form would be better. Implementing each field a stream would be a-okay, but also an overkill. Streaming the change of entire form would also cover the individual fields. So, anyone interested in subscribing the event change on one field might as well subscribe to the entire form stream and get its value.

The strem should send the instantValue or savedValues? I think that should be instantValues

I'm not quite much familiar with the underlying concept of this project. So I have one question: Can we save an invalid form? I ask this because there is a saveAndValidate method, which implies that it is actually saving even though the form is invalid. So:

deandreamatias commented 1 year ago

Yes, can save invalid value

wildsurfer commented 1 year ago

+1 for this request

ozz-rjq commented 1 year ago

need this too

sharpsan commented 6 months ago

This would be a useful feature

erayerdin commented 6 months ago

It's been a couple of months since I started working on this feature but the current API is so focal on event-driven approach[^1] that trying to implement stream-driven approach is such a hassle and I don't have time to take it on unfortunately. I've initially tried this on #1162, which is pretty much abandoned.

If the requesters are in a dire need, they can check out streaming_forms, a project that I started. It even has a web-based demo as well. It relies on stream-driven approach and raw material components. It is still in alpha phase, but can work on it in small steps if it shows further interest.

[^1]: It is not a terrible decision per se. It is a quite mature project. Async streams were not a thing in Dart back in the day, so the decision is sensible in its own regard.