API Reference
This page provides a quick reference for the core Ack classes, methods, and annotations. For detailed explanations and usage examples, refer to the specific guides linked below.
Core Ack
Class
Entry point for creating schemas. See Schema Types.
Ack.string
: Creates aStringSchema
.Ack.int
: Creates anIntSchema
.Ack.double
: Creates aDoubleSchema
.Ack.boolean
: Creates aBooleanSchema
.Ack.list(AckSchema itemSchema)
: Creates aListSchema
.Ack.object(...)
: Creates anObjectSchema
.
AckSchema<T>
(Base Class)
Base class for all schema types.
Result<T> validate(dynamic data)
: Validates the input data against the schema.AckSchema<T?> nullable()
: Returns a new schema that also acceptsnull
.AckSchema<T> description(String description)
: Adds a description (used bytoJsonSchema()
).AckSchema<T> defaultValue(T value)
: Sets a default value (used bytoJsonSchema()
).AckSchema<T> constrain(...)
: Applies a custom validation constraint.Map<String, dynamic> toJsonSchema()
: Converts the schema to a JSON Schema Object map (requirespackage:ack/json_schema.dart
).
See also TypeSafe Schemas for working with schemas and Dart models.
StringSchema
Schema for validating strings. See String Constraints.
IntSchema
/ DoubleSchema
(Number Schemas)
Schemas for validating numbers. See Number Constraints.
BooleanSchema
Schema for validating booleans. See Boolean Schema. No specific constraints beyond type.
ListSchema<E>
Schema for validating lists. See List Constraints.
ObjectSchema
Schema for validating objects (maps). See Object Schema.
- Constructed using
Ack.object(...)
. - Configuration includes
properties
,required
,additionalProperties
.
Result<T>
Object returned by validate()
. See The Result Object.
bool isOk
bool isFail
T getOrThrow()
T? getOrNull()
SchemaError? getError()
T getOrElse(T Function() defaultValue)
SchemaError
(and Subclasses)
Object representing a validation failure. See Understanding SchemaError and Error Types.
String name
String message
List<String> path
dynamic value
dynamic expected
Subclasses: SchemaTypeError
, SchemaRequiredError
, SchemaConstraintsError
, SchemaNestedError
.
SchemaConstraint<T>
Base class for creating custom validation rules. See Custom Validation Guide.
SchemaConstraint({required String name, required String message})
bool validate(T value, [Map<String, dynamic>? data])
Code Generation (ack_generator
)
Annotations for use on model classes when using code generation. See Code Generation Guide.
Class Annotations: @Schema(...)
Property Annotations: @Required
, @Nullable
, @Description
, @IsEmail
, @IsUrl
, @IsDate
, @IsDateTime
, @MinLength
, @MaxLength
, @Length
, @Matches
, @Contains
, @IsNotEmpty
, @EnumValues
, @Min
, @Max
, @Positive
, @Negative
, @MultipleOf
, @MinItems
, @MaxItems
, @UniqueItems
.
Refer to the individual guides for detailed usage and examples.