AckModel class
Annotation to mark a class for schema generation.
Generates a schema constant for validating data against your class structure.
For type-safe access to validated data, use @AckType on schema variables.
This annotation can be used in two main ways:
Regular Models
Generate schema validation for a class:
@AckModel()
class User {
final String name;
final int age;
User({required this.name, required this.age});
}
Discriminated Types (Polymorphic Models)
Generate discriminated schemas for inheritance hierarchies:
Base Class (Abstract)
Use discriminatedKey to specify the field that determines the type:
@AckModel(discriminatedKey: 'type')
abstract class Animal {
String get type;
}
Concrete Implementations
Use discriminatedValue to specify this class's discriminator value:
@AckModel(discriminatedValue: 'cat')
class Cat extends Animal {
@override
String get type => 'cat';
final bool meow;
Cat({required this.meow});
}
@AckModel(discriminatedValue: 'dog')
class Dog extends Animal {
@override
String get type => 'dog';
final bool bark;
Dog({required this.bark});
}
This generates:
final animalSchema = Ack.discriminated(
discriminatorKey: 'type',
schemas: {
'cat': catSchema,
'dog': dogSchema,
},
);
- Annotations
-
- @Target.new({TargetKind.classType})
Constructors
Properties
- additionalProperties → bool
-
Whether to allow additional properties not defined in the schema
final
- additionalPropertiesField → String?
-
The name of the field that should store additional properties
Must be a
Map<String, dynamic>field in your classfinal - description → String?
-
Optional description for the schema
final
- discriminatedKey → String?
-
Field name to use for discriminating between types in a polymorphic hierarchy.
Use this on abstract/base classes to indicate which field contains the type discriminator.
Example: @AckModel(discriminatedKey: 'type')
Cannot be used together with discriminatedValue.
final
- discriminatedValue → String?
-
The discriminator value this class represents in a polymorphic hierarchy.
Use this on concrete classes that extend an abstract class with discriminatedKey.
Example: @AckModel(discriminatedValue: 'cat')
Cannot be used together with discriminatedKey.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- schemaName → String?
-
Optional custom schema class name
final
Methods
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited