Installation
Requirements
Section titled “Requirements”| Minimum | |
|---|---|
| Dart SDK | 3.11 |
| Flutter | 3.41 |
analyzer resolved by your project, for luthor_generator |
10, up to and including 14 |
luthor has no dependencies. luthor_generator works with freezed, json_serializable, dart_mappable, and plain classes with a fromJson. Those packages are optional companions. On Dart 3.11, use freezed 3.2.x; freezed 4 needs Dart 3.13 or later.
Add luthor
Section titled “Add luthor”dart pub add luthorflutter pub add luthorEither command adds the dependency to pubspec.yaml:
dependencies: luthor: ^1.0.0Import the package in each file that builds a validator.
import 'package:luthor/luthor.dart';Add luthor_generator
Section titled “Add luthor_generator”Skip this section if you will write every schema by hand. The generator reads classes annotated with @luthor and writes a schema, a validate function, and typed keys for each one. It runs through build_runner and needs no build.yaml.
dart pub add dev:build_runner dev:luthor_generatorflutter pub add dev:build_runner dev:luthor_generatordev_dependencies: build_runner: ^2.16.0 luthor_generator: ^1.0.0Add the companion for your models alongside it. With freezed:
dart pub add freezed_annotation json_annotationdart pub add dev:freezed dev:json_serializableWith dart_mappable:
dart pub add dart_mappabledart pub add dev:dart_mappable_builderModels without freezed covers json_serializable on its own, plain classes, and dart_mappable.
Run the generator after you change an annotated class:
dart run build_runner buildUse watch instead of build to regenerate on save.
Check the install
Section titled “Check the install”Run this file.
import 'package:luthor/luthor.dart';
void main() { final email = l.string().email().required();}ValidationSuccess(data: [email protected])ValidationFailure(errors: {(root): [value must be a valid email address]})ValidationFailure(errors: {email: [email must be a valid email address]})Next: Your first validator.