Overview
External data can’t be trusted. APIs change, users mistype, and JSON drifts from what your code expects. Ack is a schema validation library for Dart and Flutter that puts a guardrail at those boundaries: describe the shape you expect once, then check untrusted data against it. You get a clear error when it doesn’t match — and your data, validated, when it does.
(“Ack” is short for “acknowledgment.”)
import 'package:ack/ack.dart';
final userSchema = Ack.object({
'name': Ack.string().minLength(2).maxLength(50),
'age': Ack.integer().min(0).max(120),
'email': Ack.string().email().nullable(),
});
final result = userSchema.safeParse({
'name': 'Ada',
'age': 36,
'email': 'ada@example.com',
});
if (result.isOk) {
print('Welcome, ${result.getOrThrow()!['name']}');
} else {
print(result.getError()); // tells you exactly which field failed, and why
}On success, getOrThrow() returns your validated data as a Map<String, Object?>. Ack checks and shapes the data — opt into code generation when you’d rather have typed getters than map access.
Why Ack?
- Guard your boundaries. Catch bad API responses, user input, and config before they reach your logic.
- Define each shape once. Reuse one schema for validation, JSON Schema export, and typed models.
- Errors you can act on. Every failure points at the exact field and the reason it failed.
- Just Dart. A fluent API with no required build step — reach for code generation only when you want it.
Go beyond validation
JSON at the edge. Rich Dart values inside.
Validate and decode strings or numbers into DateTime, Uri, Duration, enums, or your own runtime type—then encode them for the next boundary.
Ack.datetime()Explore codecs →Code generationKeep the schema. Add a typed API.
Add @AckType() to the schema you already trust and generate lightweight wrappers with typed getters, parse helpers, and no duplicated model.
UserType.parse(json)Generate typed schemas →What do you want to do?
- Validate an API response — Quickstart Tutorial, then JSON Serialization
- Show field errors in a Flutter form — Flutter Form Validation
- Make a field optional or nullable — Optional vs nullable
- Parse dates, URIs, and durations — Codecs
- Add custom validation logic — Custom Validation
- Generate typed models (no manual casts) — TypeSafe Schemas
- Reuse and compose schemas — Common Recipes
Install
dart pub add ackNew here? The Quickstart Tutorial takes you from install to handling every validation outcome in a few minutes.
Learn more
- Schema Types — every schema type and how to compose them
- Validation Rules — built-in constraints
- Error Handling — read and display structured errors
- JSON Serialization — validate and encode JSON
- API Reference — the full surface
Building with an AI agent? Start at /ack/llms.txt for a compact, machine-readable index.