complete method

Future<bool> complete()

Implementation

Future<bool> complete() async {
  busy = true;

  bool ok = true;

  // Post Sub-Forms
  for (IForm form in forms) {
    ok = await form.complete();
    if (!ok) break;
  }

  // validate the form in the complete method.
  bool validated = (await validate() == null);

  // Save the Form and pass the validation check so validate is not called a second time. This is so the form is always saved on complete.
  hive_form.Form? form =
      await save(previouslyValidated: true, validation: validated);

  if (!validated) {
    busy = false;
    return false;
  }

  // Post the Form
  if (ok) ok = await _post(form);

  // Set Clean
  if (ok == true) clean = true;

  // fire on complete events
  if (ok && _oncomplete != null) {
    ok = await EventHandler(this).execute(_oncomplete);
  }

  busy = false;

  // Set Complete
  status = StatusCodes.complete;

  return ok;
}