fluent_validation 1.0.1

  • Readme
  • Changelog
  • Example
  • Installing
  • 65

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).isNotNull().greaterThanOrEqual(13);
		ruleFor((user) => user.name).isNotEmpty();

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

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

[1.0.1] - Fix bugs in number comparison #

* Treat numbers and num and not doubles

[1.0.0] - Package Improvements #

* Changes to make the package more listable

[0.0.1] - First Implementation #

* Basic functionality
* Common expressions and extension via must
* Basic testing


import 'package:fluent_validation/fluent_validation.dart';
import 'models/user.dart';
import 'validators/user_validator.dart';

void main() {
  final User user = User("Ryan", "Sample Address", 26);
  final UserValidator userValidator = UserValidator();
  final ValidationResult validationResult = userValidator.validate(user);
  if (validationResult.hasError) {
    // Handle Error

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:

  fluent_validation: ^1.0.1

2. Install it

You can install packages from the command line:

with pub:

$ pub get

with Flutter:

$ flutter pub get

Alternatively, your editor might support pub get or flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:

import 'package:fluent_validation/fluent_validation.dart';
Describes how popular the package is relative to other packages. [more]
Code health derived from static analysis. [more]
Reflects how tidy and up-to-date the package is. [more]
Weighted score of the above. [more]
Learn more about scoring.

We analyzed this package on Jul 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.13

Health suggestions

Format lib/builders/abstract_rule_builder.dart.

Run dartfmt to format lib/builders/abstract_rule_builder.dart.

Format lib/constants/common_regex.dart.

Run dartfmt to format lib/constants/common_regex.dart.

Format lib/factories/abstract_validator.dart.

Run dartfmt to format lib/factories/abstract_validator.dart.

Format lib/fluent_validation.dart.

Run dartfmt to format lib/fluent_validation.dart.

Format lib/models/validation_result.dart.

Run dartfmt to format lib/models/validation_result.dart.


Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
Dev dependencies
test ^1.12.0