isRequired method

bool isRequired(
  1. String attribute
)

Check if a form attribute is marked as required.

The isRequired function is used to determine whether a specific form attribute is marked as required. It retrieves the validation rules associated with the attribute using the getRule function and checks if any of those rules are of the Required type. If at least one Required validation rule is found, the function returns true, indicating that the attribute is required; otherwise, it returns false.

Parameters:

  • attribute: The identifier of the form attribute to check for being required.

Returns: true if the form attribute is marked as required; otherwise, false.

Implementation

bool isRequired(String attribute) {
  final rules = getRule(attribute).where(
    (element) => element.ruleKey == Required.key,
  );
  return rules.isNotEmpty;
}