submit method

dynamic submit({
  1. required dynamic onSuccess(
    1. dynamic value
    ),
  2. dynamic onFailure(
    1. Exception exception
    )?,
  3. bool showToastError = true,
})

Submit the form If the form is valid, it will call the onSuccess function

Implementation

submit(
    {required Function(dynamic value) onSuccess,
    Function(Exception exception)? onFailure,
    bool showToastError = true}) {
  Map<String, dynamic> rules = getValidate;
  if (rules.isEmpty) {
    Map<String, dynamic> currentData = data();
    // convert all keys to lowercase with underscores
    Map<String, dynamic> newData = {};
    for (var entry in currentData.entries) {
      newData[entry.key.toLowerCase().replaceAll(" ", "_")] = entry.value;
    }
    onSuccess(newData);
    return;
  }

  NyForm.submit(stateName,
      onSuccess: onSuccess,
      onFailure: onFailure,
      showToastError: showToastError);
}