ack 1.0.0-beta.10 copy "ack: ^1.0.0-beta.10" to clipboard
ack: ^1.0.0-beta.10 copied to clipboard

A simple validation library for Dart

Ack #

pub package CI/CD docs.page

Ack is a schema validation library for Dart and Flutter that helps you validate data with a simple, fluent API. Ack is short for "acknowledge".

Why Use Ack? #

  • Simplify Validation: Easily handle complex data validation logic
  • Validate external payloads: Guard API and user inputs by validating required fields, types, and constraints at boundaries
  • Single Source of Truth: Define data structures and rules in one place
  • Reduce Boilerplate: Minimize repetitive code for validation and JSON conversion
  • Type Safety: Generate type-safe schema classes from your Dart models

Quick Start #

dart pub add ack
import 'package:ack/ack.dart';

// Define a schema for a user object
final userSchema = Ack.object({
  'name': Ack.string().minLength(2).maxLength(50),
  'email': Ack.string().email(),
  'age': Ack.integer().min(0).max(120).optional(),
});

// Validate data against the schema
final result = userSchema.safeParse({
  'name': 'John Doe',
  'email': 'john@example.com',
  'age': 30,
});

if (result.isOk) {
  final validData = result.getOrThrow();
  print('Valid user: $validData');
} else {
  final error = result.getError();
  print('Validation failed: $error');
}

Use .optional() when a field may be omitted entirely. Chain .nullable() if a present field may hold null, or combine both for an optional-and-nullable value.

Documentation #

55
likes
140
points
1.17k
downloads

Publisher

verified publisherleoafarias.com

Weekly Downloads

A simple validation library for Dart

Homepage
Repository (GitHub)
View/report issues

License

BSD-3-Clause (license)

Dependencies

collection, meta

More

Packages that depend on ack