Checkit is a modular, extensible validation library for Dart. It supports validation chains, localization, custom rules, and flexible configuration. Perfect for both client and server use cases.
- Simple and readable builder-style API
- Custom validators
- Localization support with easy customization
- String, num, int, double, string-date, datetime, IP, password and subnet validators
- Easy to extend and integrate
- Zero dependencies (pure Dart)
Add the following dependency to your project:
dependencies:
checkit: ^1.0.0Or run via CLI for Dart:
dart pub add checkitOr for Flutter:
flutter pub add checkitimport 'package:checkit/checkit.dart';
final result = Checkit.string
.min(5)
.max(10)
.email()
.validateOnce("example@mail.com");
if (result.isValid) {
print("Success!");
} else {
print("Error: ${result.errors}");
}Or even simpler with prettyPrint() method:
import 'package:checkit/checkit.dart';
final result = Checkit.string
.min(5)
.max(10)
.email()
.validateOnce("example@mail.com");
result.prettyPrint();Checkit.string
.min(3)
.max(20)
.startsWith("abc")
.validateOnce("abc123");Available String Validations:
- min, max, exact, range
- alpha, alphanumeric
- contains, hasSymbols, hasRepeats
- isDouble, isInt
- jwt, pattern
- equals, endsWith, startsWith
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
And refs to other nodes:
- dateTime, dateTimeAuto, dateTimeIso
- password
- ip, subnet
Checkit.num
.positive()
.range(10, 100)
.validateOnce(42);Available Num Validations:
- min, max, range
- positive, negative
- multiple
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit.int
.positive()
.range(10, 100)
.validateOnce(42);Available Num Validations:
- min, max, range, rangeWithStep
- positive, negative
- multiple
- digitCount
- divisibleBy
- even, odd, prime
- oneOf
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit.double
.positive()
.range(10, 100)
.validateOnce(42);Available Double Validations:
- min, max, range
- positive, negative
- decimal, finite, integer
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit.string
.password()
.min(8)
.hasUppercase()
.hasDigit()
.noSpace()
.validateOnce("S3cureP@ss");Available Password Validations:
- typical, simple, strong
- min, max, exact
- hasUppercase, hasLowercase, hasDigit, hasLetter, hasSpecial, hasSymbols
- noSpace, noRepeats
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit.string
.dateTime("yyyy-MM-dd")
.notFuture()
.validateOnce("2023-12-01");Be careful, as it can determine the month and day values ββitself through the method for cases when the date does not give an unambiguous correspondence.
Checkit.string
.dateTimeAuto()
.notFuture()
.validateOnce("2023/12/01");Available Date (String) Validations:
- format
- maxYear, minYear
- notPast, notFuture
- before, after, range
- leapYear
- iso8601
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit.dateTime.notFuture().validateOnce(DateTime(2023, 12, 1));
Available DateTime Validations:
- maxYear, minYear
- notPast, notFuture
- before, after, range
- leapYear
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit.string.ip().v4().validateOnce("192.168.0.1");Available IP Validations:
- v4, v6
- inSubnet
- linkLocal, localhost, loopback
- range
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit.string.subnet("192.168.0.0/24").contains("192.168.0.42");Available Subnet Validations:
- contains
Special methods:
- custom, not, clone, withContext, build, validateOnce, any, every
Checkit supports expressive validation chains β including the ability to invert any validator using the .not(...) method. This allows you to declare what a value must not contain in a readable, declarative way.
For example, imagine you want to validate that a password must contain certain characters (e.g., "B", "C", "D"), but must not contain "A" or "F". With Checkit, this becomes simple and expressive:
void main() {
final validator = Checkit.string
.password()
.not(StringValidator.hasSymbols('A'), error: 'Value must not be A')
.hasSymbols('BCD')
.not(StringValidator.hasSymbols('F'), error: 'Value must not be F');
final password = 'ABCDEF';
final result = validator.validateOnce(password);
result.prettyPrint();
}β Invalid
1. Value must not be A
2. Value must not be FAny standard validator can be inverted via:
.not(validator, error: 'Custom error message')You can globally configure Checkit:
Checkit.config = ValidatorConfig(
stopOnFirstError: true,
usePermanentCache: true,
);Or use your own ValidationContext:
final context = Checkit.config.copyWith(stopOnFirstError: false).buildContext();
Checkit.string.withContext(context).min(5).validateOnce("test");Checkit uses English error messages by default. You can provide your own:
Checkit.config = ValidatorConfig(
errors: MyCustomErrors(), // Implements ICheckitErrors
);You can also integrate intl using an optional checkit_intl package (planned).
Create your own validator:
class CustomValidator {
static Validator<String> onlyLowercase({String? error}) {
return (value, context) {
if (value != null && value == value.toLowerCase()) return null;
return error ?? context.errors.generalErrors.invalidValue;
};
}
}
// Usage:
Checkit.string.custom(CustomValidator.onlyLowercase(), error: "Lowercase only");final result = Checkit.string.min(5).validateOnce("hi");
expect(result.isValid, false);
expect(result.errors.first.message, contains("Minimum 5 characters"));Checkitβ Main entry pointValidatorConfigβ Global configurationValidationContextβ Execution contextICheckitErrorsβ Localization interfaceValidatorSetβ Set of validatorsValidatorNode<T>β Builder-style chain
- β Custom rules support
- β Localization support
- β³
intlintegration - β³ Flutter adapter (AppLocalizations integration)
Crafted with care and a focus on performance. Contributions, issues, and stars are always welcome!
