FLUTTER ECOSYSTEM

SKLn-Rad/Dart-Fluent-Validation

C# fluent validation 的 Dart 版本

Dart-Fluent-Validation 项目封面
Stars
6
Forks
9
最近推送(UTC)
2023年4月17日
项目状态
未归档
Ryan Dixon GitHub avatar
GITHUB User

Ryan Dixon ↗

N̢̬͖̻̤̝̘͇̝͔͔͔̼̖̘̻͖̖̯̐́ͩ́̕͝͠e̞͇̙̤͘͏̶̵̸̰͕͇͇̲̳̖̗̭͓͔̱͖̠̉͆͞r̶̨̧̦͉̭̼̝͚̰͕͇̘̟͇̯̬̥̼̪̐̎̕̕̕ͅd̴̸̬̪͎͔͚̩̭̺ͪ͏̧̛̲̣̥͉͍̝̭̯̦̖̌͢

AJ Bell / inqVineBristol, UK官方网站 ↗
语言Dart

此仓库发布的插件

使用的依赖

依赖清单 2 项

原始 README

以下为英文项目原文快照,最新内容请访问 GitHub。

展开 / 收起项目 README

Fluent Validation

This is a port of the C# variant as can be seen at This Link

The goal with this was to decouple the UI validation as seen in Flutters TextFields and use a more common and readable standard. It is still very much beta so please give it a go and give me your feedback.

class UserValidator extends AbstractValidator<User> {
	UserValidator() {
		ruleFor((user) => user.age, key: 'age').isNotNull().greaterThanOrEqual(13);
		ruleFor((user) => user.name, key: 'name').isNotEmpty();
	}
}

// Later on
final UserValidator validator = UserValidator();
ValidationResult result = validator.validate(user);

result.errors.first.key == 'The key of the rule that errored (for example age)'
result.errors.first.message == 'The supplied error message (Passed by you, or default)'
result.errors.first.code == 'The error code'

Features

  1. Built in validators (Most included, as well as some extra ones)
  2. Custom validators (Only supported through the 'must' matcher at the moment)
  3. Localisation (Not done yet)

Built in Validators

  • isNull - (checks the object is null)
  • isNotNull - (checks the object is not null)
  • notEmpty - (checks the object is a String and not empty)
  • empty - (checks the object is a String and is empty)
  • notEqual - (checks if an object is not equal to another)
  • equal - (checks if an object is equal to another)
  • length - (checks the object is a String and is between two other numbers)
  • minLength - (checks the object is a String and is of a minimum length)
  • maxLength - (checks the object is a String and is at least of a maximum length)
  • lessThan - (checks the object is a number and is less than another number)
  • lessThanOrEqual - (checks the object is a number and is less than or equal to another number)
  • greaterThan - (checks the object is a number and is greater than another number)
  • greaterThanOrEqual - (checks the object is a number and is greater than or equal to another number)

Extra Built In Validators

These are not included in the default C# version.

  • isValidEmailAddress - (checks the object is a String and is a valid email address)
  • isValidPhoneNumber - (checks the object is a String and is a valid phone number)
  • isValidNationalInsuranceNumber - (checks the object is a String and is a valid UK national insurance number)
  • isValidUKPostCode - (checks the object is a String and is a valid UK post code)

Contributing

Feel free to do a pull request with any ideas and I will check each one. ¬ Rad