Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide Streams for FormBuilderState #1155

Open
erayerdin opened this issue Nov 25, 2022 · 7 comments · May be fixed by #1162
Open

Provide Streams for FormBuilderState #1155

erayerdin opened this issue Nov 25, 2022 · 7 comments · May be fixed by #1162
Labels
enhancement New feature or request

Comments

@erayerdin
Copy link
Contributor

erayerdin commented Nov 25, 2022

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.

@erayerdin erayerdin added the enhancement New feature or request label Nov 25, 2022
@erayerdin erayerdin changed the title Provide Value and Error Streams for FormBuilderState Provide Streams for FormBuilderState Nov 25, 2022
@deandreamatias
Copy link
Collaborator

This will be a nice feature. Things to consider:

  • This onChange should be apply only entire form, for single fields or for both?
  • The strem should send the instantValue or savedValues? I think that should be instantValues
  • Idea to implement: can be create a streamController on FormBuilder or FormBuilderField and send event each time that call onChange (on setInternalFieldValue or didChange). Is importante dispose this stream when dispose widget or remove field.

@erayerdin
Copy link
Contributor Author

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:

  • if the answer is yes, we can save invalid forms, then the stream should send saved values, not instant ones. Since FormBuilderState.fields is type of Map<String, FormBuilderFieldState> and FormBuilderFieldState has many methods to check errors such as hasError and errorText, any dev can actually extract the errors with simple where on the Map.
  • if the answer is no, we can't save invalid forms (which doesn't look so): then the stream should send instant ones or there should be two different streams for instant and saved values, like onInstantChanged ond onSaveChanged.

@deandreamatias
Copy link
Collaborator

Yes, can save invalid value

@erayerdin erayerdin linked a pull request Dec 5, 2022 that will close this issue
5 tasks
@wildsurfer
Copy link

+1 for this request

@ozz-rjq
Copy link

ozz-rjq commented May 12, 2023

need this too

@sharpsan
Copy link

This would be a useful feature

@erayerdin
Copy link
Contributor Author

erayerdin commented Apr 12, 2024

It's been a couple of months since I started working on this feature but the current API is so focal on event-driven approach1 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.

Footnotes

  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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants