Skip to Content
DocsAckGetting StartedInstallation

Installing Ack

Ack is a pure-Dart package with no required build step. Add the core library — and, optionally, the code generator for immutable models.

Add to your project

Add Ack to your project using the Dart CLI:

# For Dart projects dart pub add ack:^2.0.0-beta.3 # For Flutter projects flutter pub add ack:^2.0.0-beta.3

These docs describe the 2.0.0-beta.3 prerelease. An unversioned dart pub add ack selects the latest stable release instead. You can also add the constraint to your pubspec.yaml:

dependencies: ack: ^2.0.0-beta.3

Optional code generator

To generate models from Ack schemas or Ack schemas from hand-written models, add ack and the generator package:

dart pub add ack:^2.0.0-beta.3 dev:ack_generator:^2.0.0-beta.3 dev:build_runner

Or add them to your pubspec.yaml:

dependencies: ack: ^2.0.0-beta.3 dev_dependencies: ack_generator: ^2.0.0-beta.3 build_runner: ^2.4.0

The generator works in both directions with one annotation, @Schemable(), and a set of Is…/Has… rule annotations such as @HasMinLength(2), all exported from package:ack/ack.dart. @Schemable() on a top-level schema generates an immutable model. @Schemable() on a hand-written class generates a public <ClassName>Schema facade and JSON helpers. There is no @AckSchema() annotation; AckSchema is the runtime schema type.

import 'package:ack/ack.dart'; part 'user.g.dart'; @Schemable() final userSchema = Ack.object({ 'name': Ack.string(), 'email': Ack.string().email(), }); @Schemable() final class const Account({@HasMinLength(2) required final String name}) with _$AccountAck { static final schema = AccountSchema.schema; static final fromJson = AccountSchema.fromJson; }

Run the generator:

dart run build_runner build

See Model Code Generation for working tutorials, supported shapes, and guidance on choosing a direction.

Next step

Import package:ack/ack.dart and you’re ready — the Quickstart Tutorial takes you from your first schema to handling every validation outcome. Upgrading from Ack 1.x? See the What’s New & Migration Guide for a complete table of changes and drop-in substitutions.

Requirements

  • Dart SDK: >=3.13.0 <4.0.0 for all Ack packages. Dart 3.13 adds the primary constructors that the class-first examples use.
  • Flutter: >=3.47.0 (which bundles Dart 3.13.0) for Flutter apps and when using ack_firebase_ai.
Last updated on