validate method

Future<List<IFormField>?> validate()

Implementation

Future<List<IFormField>?> validate() async {
  // Force Close
  WidgetModel.unfocus();

  // Commit the Form
  var missing = await _getMissing();
  if (missing?.isNotEmpty == true) {
    // display toast message
    String msg =
        phrase.warningMandatory.replaceAll('{#}', missing!.length.toString());
    System.toast("${phrase.warning} $msg");

    // scroll to the field
    var view = findListenerOfExactType(FormViewState);
    //TODO: when field is cleared, scroll to the next alarming field without validation.
    if (view is FormViewState) view.show(missing.first);

    return missing;
  }

  var alarms = await _getAlarms();
  if (alarms?.isNotEmpty == true) {
    // display toast message
    String msg =
        phrase.warningAlarms.replaceAll('{#}', alarms!.length.toString());
    System.toast("${phrase.warning} $msg");

    // scroll to the field
    var view = findListenerOfExactType(FormViewState);
    if (view is FormViewState) view.show(alarms.first);

    return alarms;
  }

  return null;
}