ValidationResult class
Result of custom attributes validation.
This class represents the result of validating custom attribute data, including validation status, error messages, warnings, and optional metadata. It provides a standardized way to communicate validation results throughout the custom attributes system.
Features
- Validation Status: Boolean flag indicating whether validation passed
- Error Messages: List of validation error messages
- Warnings: List of validation warning messages
- Metadata: Optional additional validation information
- Factory Constructors: Convenient factory methods for common scenarios
- JSON Serialization: Support for JSON serialization/deserialization
- Equality Support: Proper equality comparison and hashCode implementation
Usage
// Create successful validation result
final success = ValidationResult.success();
// Create failed validation result
final failure = ValidationResult.failure(['Invalid email format']);
// Create result with warnings
final withWarnings = ValidationResult.withWarnings(['Price seems high']);
// Check validation status
if (result.isValid) {
// Proceed with valid data
} else {
// Handle validation errors
for (final error in result.errors) {
print('Error: $error');
}
}
Constructors
-
ValidationResult.new({required bool isValid, List<
String> errors = const [], List<String> warnings = const [], Map<String, dynamic> ? metadata}) -
const
-
ValidationResult.failure(List<
String> errors) -
Create a failed validation result with errors
factory
-
ValidationResult.fromJson(Map<
String, dynamic> json) -
Create from JSON
factory
- ValidationResult.success()
-
Create a successful validation result
factory
-
ValidationResult.withWarnings(List<
String> warnings) -
Create a validation result with warnings
factory
Properties
-
allIssues
→ List<
String> -
Get all issues as a single list
no setter
-
errors
→ List<
String> -
final
- hashCode → int
-
The hash code for this object.
no setteroverride
- hasIssues → bool
-
Check if validation has any issues (errors or warnings)
no setter
- isValid → bool
-
final
-
metadata
→ Map<
String, dynamic> ? -
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
-
warnings
→ List<
String> -
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toJson(
) → Map< String, dynamic> - Convert to JSON
-
toString(
) → String -
A string representation of this object.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
override