validateAndSave method
void
validateAndSave({
- required Future<
SaveResult> saveWork()?, - void onFailure(
- SaveResult result
- void onSuccess(
- SaveResult result
Implementation
void validateAndSave({
required Future<SaveResult> Function()? saveWork,
void Function(SaveResult result)? onFailure,
void Function(SaveResult result)? onSuccess}) async
{
fieldErrors.clear();
bool success = validate();
if (!success) {
return;
}
if (saveWork == null) {
return;
}
SaveResult result = await saveWork();
if (result.status == SaveStatus.validationFailed) {
if (result.hasFieldErrors) {
fieldErrors.addAll(result.fieldErrors!);
validate();
}
}
Function(SaveResult)? fn = result.success ? onSuccess : onFailure;
if (fn != null) {
fn(result);
}
}