01 / DEFINEWrite the contract once.
Compose small schemas into the exact object your application accepts. Constraints stay beside the fields they protect.
Explore schemas → user_schema.dartCONTRACT
final userSchema = Ack.object({
'name': Ack.string().minLength(2),
'email': Ack.string().email(),
'createdAt': Ack.datetime(),
});
02 / VALIDATECheck data where it enters.
Use safeParse at an API, form, storage, or AI boundary. The result makes success and failure deliberate—without a required try/catch.
Choose a parsing strategy → incoming payloadUNKNOWN → CHECKED
final result = userSchema
.safeParse(request.body);
if (result.isFail) {
logger.warn(result.getError());
}
01BOUNDARY VALUEObject?
02RUN THE SCHEMAsafeParse()
03TYPED OUTCOMESchemaResult
03 / USE THE RESULTHandle both outcomes with context.
Consume the validated value or route a structured error. Every failure preserves the path and reason your UI, logs, or API response needs.
Work with SchemaResult → OKresult.getOrThrow()
Validated mapOnly the shape you described moves forward.
FAILresult.getError()
SchemaError#/email pinpoints the invalid field.