getErrorMessage method

String? getErrorMessage(
  1. String attribute
)

Get the first error message associated with a form attribute.

The getErrorMessage function is used to retrieve the first error message associated with a specific form attribute. It first retrieves the list of error messages using the getErrorMessages function and checks if there are any error messages. If error messages exist, it returns the first error message in the list. If no error messages are associated with the attribute, the function returns null.

Parameters:

  • attribute: The identifier of the form attribute for which you want to retrieve the first error message.

Returns: The first error message associated with the specified form attribute, or null if no error messages are found.

Implementation

String? getErrorMessage(String attribute) {
  List<String> errors = getErrorMessages(attribute) ?? [];
  if (errors.isNotEmpty) {
    return errors[0];
  }
  return null;
}