Invariant class abstract mixin

Provides checks for object invariants, preconditions, and postconditions.

In ContractCheckingMode.assertionsOnly, failed checks use Dart assertions. In ContractCheckingMode.alwaysThrow, failed checks throw a ContractViolationError.

Constructors

Invariant()

Properties

contractCheckingMode → ContractCheckingMode
The mode used when evaluating this object's contracts.
no setter
hashCode → int
The hash code for this object.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

invariant() → bool
Returns whether this object is in a valid state.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
post({required bool condition(), required String message()}) → void
Checks a postcondition.
pre({required bool condition(), required String message()}) → void
Checks a precondition.
runWithInvariant<R>(String description, R body()) → R
Runs body and evaluates invariant afterward, even if body throws.
runWithInvariantAsync<R>(String description, Future<R> body()) → Future<R>
Runs body and evaluates invariant afterward, even if body throws.
toString() → String
A string representation of this object.
inherited
verifyInvariant(String description) → void
Checks whether this object's invariant currently holds.

Operators

operator ==(Object other) → bool
The equality operator.
inherited