Assert<T> class

A decorator that allows adding assert(...) on the generated classes.

Usage example:

@valueClass
class Email with _$Email {
  @Assert(_checkNotEmpty, 'Email cannot be empty')
  @Assert(_checkFormat, 'Email format is invalid')
  factory Email(String value) = _Email;

  factory Email.fromJson(String value) = _Email;
}

bool _checkNotEmpty(String value) => value.isNotEmpty;
bool _checkFormat(String value) => value.contains(RegExp(r'^.+@\S+\.\S+$'));

TODO: @Target({TargetKind.constructor}) see: https://github.com/dart-lang/sdk/issues/47421

Constructors

Assert(bool eval(T), [String? message])
const

Properties

eval bool Function(T)
final
hashCode int
The hash code for this object.
no setterinherited
message String?
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

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