dart_data_generator 0.1.1 copy "dart_data_generator: ^0.1.1" to clipboard
dart_data_generator: ^0.1.1 copied to clipboard

Code generator for dart_data. Generates ModelSchema implementations, serialization, typed repositories, and migration diffs from @SyncModel annotations via build_runner.

dart_data_generator #

pub package CI License: BSD-3

Code generator for dart_data — the SwiftData for Flutter.

Generates ModelSchema implementations, toJson/fromJson serialization, typed repositories, and migration diffs from @SyncModel annotations. No hand-written boilerplate.

Installation #

dependencies:
  dart_data: ^0.1.0

dev_dependencies:
  dart_data_generator: ^0.1.0
  build_runner: ^2.4.0

Usage #

1. Annotate your model #

import 'package:dart_data/dart_data.dart';

@SyncModel(tableName: 'todos')
class Todo {
  @SyncId()
  final String id;

  @SyncField(index: true)
  final String title;

  @SyncField()
  final bool completed;

  @SyncField(nullable: true, columnName: 'due_date')
  final DateTime? dueDate;

  Todo({required this.id, required this.title, this.completed = false, this.dueDate});
}

2. Run the generator #

dart run build_runner build

This generates a *.g.dart file containing:

  • TodoSchema — full ModelSchema<Todo> implementation with column definitions, indexes, and serialization
  • Type-safe query helpers
  • Migration diff support for schema versioning

3. Use the generated schema #

final dd = await DartData.initialize(
  databasePath: 'app.db',
  schemas: [TodoSchema()],
);

final repo = dd.repository<Todo>(TodoSchema());
await repo.save(Todo(id: '', title: 'Ship it'));

Annotations #

Annotation Target Description
@SyncModel() Class Marks a class for schema generation. Optional tableName.
@SyncId() Field Primary key. Auto-generates UUID if empty string is passed.
@SyncField() Field Persisted column. Options: index, nullable, columnName.
@SyncIgnore() Field Excluded from persistence.
@SyncIndex() Class Composite index definition.

Learn More #

See the dart_data documentation for full framework docs.

License #

BSD 3-Clause. See LICENSE.

0
likes
130
points
69
downloads

Publisher

unverified uploader

Weekly Downloads

Code generator for dart_data. Generates ModelSchema implementations, serialization, typed repositories, and migration diffs from @SyncModel annotations via build_runner.

Topics

#code-generation #build-runner #database #sqlite #persistence

Documentation

API reference

License

BSD-3-Clause (license)

Dependencies

analyzer, build, code_builder, dart_data, dart_style, source_gen

More

Packages that depend on dart_data_generator