You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Illustrates more complex validation with multiple rules (IsRequired, MinLength, MaxLength).
The onFailureCallBack is triggered for any rule failure, logging the input and the failed rule for analysis.
TextFormField(
decoration:constInputDecoration(labelText:'IsRequired'),
validator:xValidator([
// Ensures that the input is not empty with a custom error message.IsRequired("Field cannot be empty"),
// Ensures that the input has a minimum length of 3 characters.MinLength(3, "Field must be at least 3 characters"),
// Ensures that the input does not exceed a maximum length of 20 characters.MaxLength(20, "Field cannot exceed 20 characters"),
], onFailureCallBack: (String? input, List<TextXValidationRule> rules, TextXValidationRule failedRule) {
// Logs information about the failed validation for further analysis.log("###### Validation failed for input #### : $input");
log("#### Failed rule #### : $failedRule");
}),
),
Explanation:
The first example demonstrates basic usage of IsRequired validation rule. It ensures that the input is not empty.
The second example uses multiple rules (IsRequired, MinLength, MaxLength) for more complex validation. It also includes an
onFailureCallBack to handle validation failures. If any rule fails, the callback is triggered, logging the input and the failed rule for further analysis.