form_bloc
form_bloc copied to clipboard
[Feature request] Add autoSubmit option with debounce time.
Proposal:
Add to the super constructor:
-
autoSubmit
: by default false, -
autoSubmitDebounceTime
by default 1000 milliseconds.
when you set autoSubmit
to true
, submit
will be called when any fieldBloc
changes its value after the debounce time, so if all fields are valid, then onSubmitting
will be called.
class MyFormBloc extends FormBloc<String, String> {
MyFormBloc()
: super(
autoSubmit: true,
autoSubmitDebounceTime: Duration(milliseconds: 500),
) {
// Add fields...
}
@override
Stream<FormBlocState<String, String>> onSubmitting() async* {
// Awesome logic...
}
}
Do you have any suggestion?
Nice! Or perhaps detect navigation away from the form instead of time based saving, and then we can have a single save event to save Firebase costs. I have been thinking about this for a while how else can we approach it then pure time based... Perhaps these two events could work together: Either starting to type in another field, validate the previous one, and if user tries to navigate away do another validation and save.
@giorgio79 sorry I don't understand, can you be clearer? :)
Sure, let me try.
So, we could have:
- time based submit: Submit after x time to Firebase
- event based submit: On user navigation to another screen User starts to type in another form fie
In the case of autosubmit it is called when a field changes its value after the debounce time.
On user navigation, you can simply capture the navigation event, in the case of a pop, you can use willPopScope and call the submit method, and use the FormBlocListener to do the actual navigation, after ensuring that the data has been stored.