SubmitFormMixin<Form extends FormControllerMixin, Result> mixin
Mixin that adds submit logic.
To use this mixin, override form and implement performSubmit, onSubmitting, onSubmitted and onSubmitError. Optionally, override concurrentSubmit to allow concurrent submits.
It can be easily used with any state management solution, eg. Riverpod, BLoC, etc.
Example (using Cubit from flutter_bloc package):
enum MyFormState { initial, submitting, success, error }
class MyFormCubit extends Cubit<MyFormState> with SubmitFormMixin<String> {
MyFormCubit() : super(MyFormState.initial);
@override
final form = MyForm();
@override
Future<String> performSubmit() async {
// perform submit logic
}
@override
void onSubmitting() {
emit(MyFormState.submitting);
}
@override
void onSubmitSuccess(String result) {
emit(MyFormState.success);
}
@override
void onSubmitError(Object error, StackTrace stackTrace) {
emit(MyFormState.error);
}
}
Properties
- concurrentSubmit → bool
-
If false, submit will be performed only if form is not already submitting.
no setter
- form → Form
-
The form that is being extended.
no setterinherited
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
onSubmitError(
Object error, StackTrace stackTrace) → void - Called when submit fails.
-
onSubmitted(
Result result) → void - Called when submit is submitted (eg. data is sent to backend).
-
onSubmitting(
) → void - Called before performing submit.
-
performSubmit(
) → Future< Result> - Performs actual submit logic, eg. sending data to the server.
-
submit(
) → Future< void> - Validates form, and if valid perform submit logic using performSubmit.
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited