fluent_validation_flutter 0.0.2 fluent_validation_flutter: ^0.0.2 copied to clipboard
FluentValidationFlutter is strongly inspired by FluentValidation for C# and is intended to bring Dart a similar experience that allows you to validate common rules in entities in a simple way.
FluentValidationFlutter #
A small Flutter package for building validation rules.
Getting Started #
This project was forked from flutter_validate (which has not been updated for a long time) and with some ideas from fluent_validation, has been updated and added some changes to make it more like using FluentValidation .NET
Simple Example #
class CustomerValidator extends AbstractValidator<Customer> {
CustomerValidator() {
ruleFor("id", (customer) => customer.id).notNull();
ruleFor("name", (customer) => customer.name).notEmpty();
ruleFor("age", (customer) => customer.age).greaterThan(18);
}
}
Customer customer = Customer();
CustomerValidator validator = new CustomerValidator();
validator.validate(customer);
bool isValid = validator.isValid();
List<String> errors = validator.allErrors;
Complex Example #
class CustomerValidator extends AbstractValidator<Customer> {
CustomerValidator() {
ruleFor("id", (customer) => customer.id)..notNull()..greaterThan(0);;
ruleFor("name", (customer) => customer.name)
..notEmpty()..notEqual(() => "Squall");;
ruleFor("age", (customer) => customer.age)
..greaterThan(18)..withMessage("Custom Message");
}
}
Customer customer = Customer();
CustomerValidator validator = new CustomerValidator();
validator.validate(customer);
bool isValid = validator.isValid();
List<String> errors = validator.allErrors;
Credits #
Forked from flutter_validate repo.
fluent_validation repo.