form_bloc icon indicating copy to clipboard operation
form_bloc copied to clipboard

[Feature request] Add autoSubmit option with debounce time.

Open GiancarloCode opened this issue 4 years ago • 4 comments

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?

GiancarloCode avatar Mar 12 '20 12:03 GiancarloCode

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 avatar Mar 12 '20 12:03 giorgio79

@giorgio79 sorry I don't understand, can you be clearer? :)

GiancarloCode avatar Mar 12 '20 12:03 GiancarloCode

Sure, let me try.

So, we could have:

  1. time based submit: Submit after x time to Firebase
  2. event based submit: On user navigation to another screen User starts to type in another form fie

giorgio79 avatar Mar 12 '20 12:03 giorgio79

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.

GiancarloCode avatar Mar 12 '20 13:03 GiancarloCode