Skip to main content

Installation

Setting up ZodArt is quick and easy:

â„šī¸ Optional: Even though using code generation is HIGHLY recomended (see why code generation), ZodArt can work without it. If you really don't want to use code generation for some reason, only Add ZodArt package.

  1. Add ZodArt package
  2. Add build_runner package
  3. Use ZodArt annotations
  4. 🚀 Recommended: Install ZodArt snippets extension

Add ZodArt package​

Add ZodArt package to your dependencies:

For Flutter project:

flutter pub add zodart

For Dart project:

dart pub add zodart

Add build_runner package​

Add build_runner package to your dependencies:

For Flutter project:

flutter pub add dev:build_runner

For Dart project:

dart pub add dev:build_runner

Use ZodArt annotations​

  1. Add a part directive into your code to include the generated code:

    import 'package:zodart/zodart.dart';

    // MANDATORY
    // Add part '<your_file_name.zodart.dart>'; so for 'code_gen_example.dart' add:
    part 'code_gen_example.zodart.dart';

    // MANDATORY when generating output class
    // Add part '<your_file_name.zodart.type.dart>'; so for 'code_gen_example.dart' add:
    part 'code_gen_example.zodart.type.dart';

    /// your code using `@ZodArt` annotation follows
  2. Run build_runner to generate the ZodArt helper / output classes

    dart run build_runner build

🚀 Recommended: Install ZodArt snippets extension for VS Code​

To simplify the schema creation use the official ZodArt Snippets extension for VS Code.

ZodArt Snippets extension

🔗 See the full working example.