Skip to content

Getting Started

📢 v1.0.0-dev Documentation

You are viewing the documentation for Validasi v1.0.0-dev (development version). This version includes significant API changes and new features, but it does not include the async variant yet and some rules may still be incomplete. Looking for the stable version? View v0 Documentation →

Welcome to Validasi! This guide will help you get started with the most flexible and type-safe validation library for Dart and Flutter.

What is Validasi?

Validasi is a powerful validation library that brings type safety, composability, and elegance to data validation in Dart and Flutter applications. Whether you're validating user input, API responses, or configuration files, Validasi makes it simple and maintainable.

Key Features

Type Safety First

Validasi is built with Dart's type system in mind, providing full type safety throughout your validation logic. No more runtime surprises!

Composable & Reusable

Create complex validation schemas from simple, reusable rules. Mix and match rules to build exactly what you need.

Performance Optimized

Built-in caching system ensures your validations run fast, even when validating thousands of objects.

Why Choose Validasi?

🎯 Intuitive API

dart
final schema = Validasi.string([
  Rules.string.minLength(3),
  Rules.string.maxLength(20),
]);

final result = schema.validate('Hello');

Simple, readable, and self-documenting code.

🔧 Comprehensive Rules

Built-in rules for every common validation scenario:

  • String validation (length, patterns, formats)
  • Number validation (ranges, comparisons)
  • Collection validation (lists, maps)
  • Custom validation (inline rules, transformations)

🌲 Nested Validation

Validate complex, nested data structures with ease:

dart
final userSchema = Validasi.map<dynamic>([
  Rules.map.hasFields({
    'profile': FieldRules<Map<String, dynamic>>([
      Rules.map.hasFields({
        'name': FieldRules<String>([Rules.string.minLength(2)]),
        'age': FieldRules<int>([Rules.number.moreThan(0)]),
      }),
    ]),
  }),
]);

🎨 Flexible Transformations

Transform data during validation:

dart
final schema = Validasi.string([
  Rules.transform<String>((value) => value?.trim().toLowerCase()),
  Rules.string.minLength(3),
]);

✅ Type-Safe Input Handling

Validasi uses dual generics to enforce input type safety at compile time. When you need to accept different input types (e.g., strings from APIs), use withPreprocess:

dart
// Accept String input, validate as int
final ageSchema = Validasi.number<int>([
  Rules.number.moreThan(0),
  Rules.number.lessThan(150),
]).withPreprocess(
  ValidasiTransformation<String, int>((value) => int.parse(value)),
);

// validate() now only accepts String at compile time
final result = ageSchema.validate('25'); // ✓ Correct type
// ageSchema.validate(25);               // ✗ Compile error

When to use withPreprocess:

  • Accepting data from JSON, APIs, or form inputs (usually strings)
  • Converting between types in a type-safe way
  • Building flexible schemas that accept specific input types

Read more in the Transformations Guide and Engine Architecture.

Community & Support

LLM Support

This documentation has support for LLMS, you can click the button at the bottom right corner to copy or download the current page as markdown file for your LLM processing. Or you can visit llms-full.txt or llms.txt files.

Released under the MIT License.