flunt_dart 0.0.3 flunt_dart: ^0.0.3 copied to clipboard
Library that provides a fluent way to use Notification Pattern.
Flunt-dart #
Library that provides a fluent way to use Notification Pattern. It is based on Flunt.
Usage #
Create a contract #
Create a contract for a attribute ou a class.
class Customer {
final String firstName;
final String lastName;
Customer(this.firstName, this.lastName);
}
class NameContract extends Contract<String> {
NameContract(String value, String name) : super(value, name) {
isNotEmpty("not should be empty");
hasMaxLen(40, "should have no more than 40 chars");
hasMinLen(3, "should have at least 3 chars");
}
}
class CustomerContract extends Contract<Customer> {
CustomerContract(
Customer customer,
) : super(customer, "Customer") {
addNotifiable(NameContract(customer.firstName, "First Name"));
addNotifiable(NameContract(customer.lastName, "Last Name"));
}
}
Use the contract #
var customer = Customer("Pedro", "Bissonho");
var customerContract = CustomerContract(customer);
if (customerContract.valid) {
// The customer is valid and can be used.
}