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 # For Flutter projects flutter pub add ack

Or add to your pubspec.yaml (check pub.dev  for the latest version):

dependencies: ack: ^1.2.0 # Replace with latest version

Optional code generator

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

dart pub add ack ack_annotations dart pub add --dev ack_generator build_runner

Or add them to your pubspec.yaml:

dependencies: ack: ^1.2.0 # Replace with latest version ack_annotations: ^1.2.0 # Replace with latest version dev_dependencies: ack_generator: ^1.2.0 # Replace with latest version build_runner: ^2.4.0

The generator works in both directions. @AckInfer() marks a top-level schema and generates an immutable model. @AckModel() marks a hand-written class and generates a public <ClassName>Schema facade, a private Ack codec, and JSON helpers. There is no @AckSchema() annotation; AckSchema is the runtime schema type.

import 'package:ack/ack.dart'; import 'package:ack_annotations/ack_annotations.dart'; part 'user.ack.dart'; part 'user.ack.g.dart'; @AckInfer() final userSchema = Ack.object({ 'name': Ack.string(), 'email': Ack.string().email(), }); @AckModel() final class Account with _$AccountAck { const Account({required this.name}); final String name; 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.

Requirements

  • Dart SDK: >=3.9.0 <4.0.0 for core ack
  • Dart SDK: >=3.9.0 <4.0.0 when using ack_annotations / ack_generator
Last updated on