rules 3.5.0
rules: ^3.5.0 copied to clipboard
Rules is a simple yet powerful and feature-rich validation library for both dart and flutter.
Changelog #
3.5.0 #
Breaking changes #
StringSchemanumeric comparison methods (greaterThan,greaterThanOrEqualTo,lessThan,lessThanOrEqualTo) now take a typednum thaninstead ofString than. Pass the bound as a number directly:.greaterThan(18)instead of.greaterThan('18'). Only the value under validation is parsed; the comparison target is no longer string-parsed
3.0.0 #
This is a complete, ground-up rewrite of the library. Everything is breaking since the 2.x line. There is no migration path. Schemas must be rebuilt using the new chaining API.
If you need the old API, pin to the last 2.x release: https://pub.dev/packages/rules/versions/2.2.0+1 (sdk: '>=2.12.0 <4.0.0'). 3.0.0 and above requires sdk: '>=3.0.0 <4.0.0'.
Breaking changes #
- Removed the single untyped
Ruleclass and its flat constructor of boolean/value flags (isRequired,isEmail,isUrl,isPhone,isIp,isNumeric,isNumericDecimal,isAlphaSpace,isAlphaNumeric,isAlphaNumericSpace,regex,length,minLength,maxLength,greaterThan,greaterThanEqualTo,lessThan,lessThanEqualTo,equalTo,notEqualTo,equalToInList,notEqualToInList,shouldMatch,shouldNotMatch,shouldPass,shouldPassOrCustomError,inList,notInList) passed in one constructor call - Removed
RuleOptions(trim,lowerCase,upperCaseas constructor options). These are now schema methods (.trim(),.toLowerCase(),.toUpperCase()) chained directly on aStringSchema - Removed
customErrorText(a single string overriding every default message on a rule) andcustomErrors(aMap<String, String>keyed by option name). Every constraint method now takes its own optionalerrorparameter directly - Removed
Rule.copyWith()andGroupRule.copyWith(). Schemas are immutable and rebuilt via chaining instead of copied and partially overridden - Removed the implicit type coercion where every value, regardless of declared constraint, was
passed and compared as a
String. Values are now strongly typed per schema (String,int,double,bool) - Removed the implicit "use
isNumericDecimalautomatically whenisNumericisn't set" behavior for numeric comparison constraints on string input. String-schema numeric comparisons now always parse both operands as decimals; integer and double schemas take typedint/doubleoperands directly and never parse strings at all - Removed
rule.error/rule.hasError/rule.valueas plain nullable getters on a mutable rule object. Replaced by the sealedRuleResult<T>returned from.parse(value), read viaok,hasError,hasValidatedValue,validatedValue, anderror, or consumed exhaustively via pattern matching orfold - Removed the old
GroupRule([rule1, rule2], name: ...)positional-list constructor.GroupRulenow takesfields: [...]as a named parameter ofValidatable(typicallyRuleField, produced byschema.bind(value)) - Removed the old
CombinedRule(rules: [...], groupRules: [...])field names. Renamed toCombinedRule(fields: [...], groups: [...]) - Removed
requiredAtleast(lowercase l) onGroupRule. Renamed torequiredAtLeast - Removed the exception thrown when a
GroupRule's field count was smaller thanrequiredAtleast. Out-of-range values are now handled gracefully by comparing against however many fields are actually present - Removed string-keyed error identification (
'isRequired','isEmail', etc. asMapkeys incustomErrors). Replaced by stable, code-comparableRuleCheckenums (StringCheck,IntCheck,DoubleCheck,BoolCheck,GroupCheck), exposed asRuleFailure.check - Removed
shouldPassandshouldPassOrCustomErroras separate, overlapping constraint slots. Unified intocheck(bool Function(T) test, {error})andrefine(String? Function(T) validator), available identically across every schema type - Removed direct boolean-flag validation of non-
Stringtypes through the singleRuleclass. Booleans, ints, and doubles each now have a dedicated schema (BoolSchema,IntSchema,DoubleSchema) with their own constraint set
New APIs #
Rule.string(name:),Rule.integer(name:),Rule.double(name:),Rule.boolean(name:)factories returningStringSchema,IntSchema,DoubleSchema,BoolSchemarespectively- Chainable builder methods on every schema, each returning a new immutable schema instance
StringSchema.trim(),.toLowerCase(),.toUpperCase()as chained transform methods, applied in that order before any constraint runs- Per-constraint
errorparameter on every builder method {name}and{value}placeholder resolution on both default and custom messages, and onrefine()return stringsRuleResult<T>sealed type (Valid<T>/Invalid<T>), withok,hasError,hasValidatedValue,validatedValue, anderrorgettersRuleResult.fold()for exhaustive resolution of both outcomes in one callcheck(bool Function(T) test, {error})on every schema typerefine(String? Function(T) validator)on every schema typeGroupRulerebuilt aroundfields: List<Validatable?>, withrequiredAll,requiredAtLeast,maxAllowed, and matching error overridesGroupResultsealed type (GroupValid/GroupInvalid)CombinedRulerebuilt aroundfields: List<Validatable?>andgroups: List<GroupRule?>, exposingfailures,errorList, andhasErrorBoolSchema.equalTo(bool to, {error})as the general form behindisTrue()/isFalse()StringSchema.regex(RegExp pattern, {error})replacing the oldmatches()naming
2.2.0+1 #
New feature:
- Added
shouldPassOrCustomError
2.1.2 #
Bug fix:
- Test fixes
2.1.1 #
New feature:
- Added support for URLs with credentials (RFC 3986 compliant) to handle authentication in URLs (
e.g.,
https://user@example.comorhttps://user:pass@example.com/path)
2.1.0 #
New feature:
- Improved
isUrlcheck to correctly validate https?://localhost and https?://
2.0.0 #
New feature:
- Added
shouldPass
2.0.0-nullsafety.0 #
Added nullsafety
1.2.0+3 #
Fixes:
- Fixed
emailvalidation
1.2.0+1 #
New feature:
- Added
trim,upperCaseandlowerCaserule options
1.1.0 #
Breaking changes:
regexnow expects a RegExp object instead of String
1.0.2+1 #
- Added copyWith extension method for Rule and GroupRule
1.0.1+7 #
- Updated and cleaned README
1.0.1+5 #
- Updates: Now 'customErrors' has higher priority than 'customErrorText'
1.0.1+4 #
- README updated
- Docs updated
1.0.0 #
- Initial release
- Rules
- GroupRules
- CombinedRules