Getting Started
📢 v1.0.0-dev Documentation
You are viewing the documentation for Validasi v1.0.0-dev (development version). 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
Through a series of optimizations, your validations run fast, even when validating thousands of objects.
Why Choose Validasi?
🎯 Intuitive API
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:
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:
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:
// Accept String input, validate as int
final ageSchema = Validasi.number<int>([
Rules.number.moreThan(0),
Rules.number.lessThan(150),
]).withPreprocess((String value) => int.parse(value));
// validate() now only accepts String at compile time
final result = ageSchema.validate('25'); // ✓ Correct type
// ageSchema.validate(25); // ✗ Compile errorWhen 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.
Companion Packages
Validasi also ships with two companion packages:
validasi_annotation+validasi_gen(experimental) — annotation-based code generation. Decorate your model with@ValidateClass()and@Validate(), and the generator produces a typedXFields<V>hierarchy plusvalidate()/validateAsync()extension. No Runtime codegen — the generator runs at build time viabuild_runner.validasi_ui(experimental) — headless form management for Flutter. AValidasiFormController<T>bridges generated schemas to the widget tree with hooks-style ergonomics:watchValue,watch,setError,formErrors. Pair it withvalidasi_genusinggenerateFields: true,generateSchema: true, andgenerateValidateForm: truefor a fully type-safe form experience.
Experimental
Both validasi_gen and validasi_ui are in active development. APIs may change without a major version bump. Feedback and contributions are welcome!
See the dedicated guides for detailed usage:
- Code Generation — using
validasi_annotation+validasi_gen - Form Management — using
validasi_uifor Flutter forms - Agent Skills — if you use an AI coding agent (Claude Code, Cursor, Codex, and others all support the open
SKILL.mdformat), these ship with the same guidance baked in so it writes correctvalidasi/validasi_gen/validasi_uicode by default. Install withnpx skills add albetnov/validasi --all
Community & Support
- GitHub: albetnov/validasi
- Issues: Report bugs or request features
- Pub.dev: Package documentation
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.
