flutter_boilerplate_generator 2.3.0 copy "flutter_boilerplate_generator: ^2.3.0" to clipboard
flutter_boilerplate_generator: ^2.3.0 copied to clipboard

A Dart code generator for Flutter boilerplate: model, entity, hive, and cubit state. Generates JSON serialization, copyWith, value equality, entity/Hive mapping, and pattern-matching extensions.

Changelog #

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

2.3.0 - 2026-06-23 #

Added #

  • di_generator.dart: new DependencyInjectionBuilder that scans all Dart source files for classes annotated with @Injectable, @Singleton, @LazySingleton, @Module, and @Named, then generates a single inject.config.dart file exposing a configureDependencies() function that registers every discovered dependency in topological order.
  • build.yaml: registered dependency_injection_builder targeting $package$ so build_runner picks it up automatically without consumer configuration.
  • builder.dart: exported the new dependencyInjectionBuilder factory alongside the existing model and state builders.
  • Example under example/lib/di/ demonstrating real-world DI wiring: ApiClient, AppConfig, GetUserUseCase, NetworkModule, UserDataSource, UserRepository, and main.dart calling the generated configureDependencies() on startup.

2.2.0 - 2026-06-22 #

Fixed #

  • state_generator.dart: generator no longer crashes when a @CubitState class contains static members or other non-factory child elements — only factory constructors are processed.
  • copy_with_helper.dart: nonDartTypeCopyWith no longer generates a nested copyWith for classes that have non-nullable constructor parameters; all parameters of the nested class must be nullable before a nested copyWith is emitted, preventing invalid optional non-nullable argument syntax.
  • model_generator.dart: when @Model(toEntity: true) is used, a clear build-time InvalidGenerationSourceError is thrown if any required parameter of the target entity class is missing from the model, rather than silently producing uncompilable generated code.
  • json_helper.dart: fromJson for List<XModel> fields now casts to a bare List before mapping, avoiding a TypeError caused by casting List<dynamic> to a typed List<T> at runtime.
  • json_helper.dart, entity_helper.dart, hive_helper.dart: Map<K, XModel> fields are now fully handled in all four serialization paths — toJson/fromJson, toEntity/fromEntity, toHiveObject/fromHiveObject — mapping each value via the appropriate conversion method instead of passing raw objects.
  • json_helper.dart: toJson for DateTime fields now emits .toIso8601String() instead of the raw object, matching the fromJson counterpart that calls DateTime.parse(...).
  • json_helper.dart: toJson for Duration fields now emits .inMicroseconds instead of the raw object, matching the fromJson counterpart that calls Duration(microseconds: ...).
  • json_helper.dart: toJson for a single nested model field (not List, not Map, not enum, not a scalar primitive) now calls .toJson() on the nested instance, preventing jsonEncode from receiving a non-serializable object.

2.1.0 - 2026-06-22 #

Fixed #

  • entity_helper.dart: List<XModel> fields now correctly map each item via .map((e) => e.toEntity()).toList() and fromEntity counterpart — previously treated as a primitive pass-through.
  • entity_helper.dart: nullable entity field passed to fromEntity now uses null-safe call (instance?.field == null ? null : Type.fromEntity(instance!.field!)) to avoid compile errors when the model field is non-null.
  • copy_with_helper.dart: multiple classes in the same source file no longer produce a duplicate const _sentinel = Object() — sentinel constant is now named per-class (e.g. _$MessageDtoSentinel).
  • copy_with_helper.dart: nonDartTypeCopyWith no longer generates nested copyWith classes that reference transitive types not imported by the consumer file — classes with List<XModel> or other non-resolvable nested types are now skipped via a recursive _isFullyResolvable check.
  • model_generator.dart: two or more fields sharing the same non-primitive type no longer produce duplicate _$XCopyWith class declarations — generation is deduped by type name.
  • model_generator.dart: non-null constructor parameters now correctly emit the required keyword in the generated _ClassName implementation.
  • json_helper.dart: fromJson no longer wraps non-null fields (no @Default) in a null check that returns null — the parsed value is used directly, matching the required constructor param.
  • json_helper.dart: toJson for List<XModel> fields now calls .map((e) => e.toJson()).toList() instead of serialising the raw object.
  • hive_helper.dart: toHiveObject and fromHiveObject now handle List<XHiveObject> fields with .map((item) => item.toHiveObject()).toList() / .map((item) => XModel.fromHiveObject(item)).toList().

2.0.0 - 2026-06-19 #

Breaking Changes #

  • Removed re-export of annotation classes (@Model, @CubitState, @JsonKey, @Default, @EnumValue) from the public API of this package. Consumers must now import package:flutter_boilerplate_annotations/flutter_boilerplate_annotations.dart directly.

Added #

  • flutter_boilerplate_annotations added as a pub.dev dependency to supply annotation classes previously bundled in this package.

Fixed #

  • field_meta_helper.dart: corrected inPackage on TypeChecker for JsonKey and Default from 'core' to 'flutter_boilerplate_annotations', so element-based annotation detection now works correctly.
  • build, source_gen, and analyzer moved from dev_dependencies to dependencies — they are imported directly by library code in lib/ and are runtime dependencies of the generator.

Changed #

  • Removed unused imports of package:flutter_boilerplate_generator/flutter_boilerplate_generator.dart from example files; annotations are now imported directly from flutter_boilerplate_annotations.

1.0.0 - 2026-06-19 #

Added #

  • ModelGenerator: generates fromJson, toJson, copyWith, ==, and hashCode for classes annotated with @Model
  • StateGenerator: generates copyWith, ==, and hashCode for classes annotated with @CubitState
  • Code generation helpers:
    • entity_helper.dart — generates entity mapping from model fields
    • json_helper.dart — generates fromJson / toJson methods
    • hive_helper.dart — generates Hive object mapping
    • copy_with_helper.dart — generates copyWith method
    • compareable_helper.dart — generates == and hashCode
    • field_meta_helper.dart — extracts field metadata from analyzer elements
    • type_helper.dart — resolves Dart type names for code generation
  • build.yaml configuration wiring ModelBuilder and StateBuilder to build_runner
  • Example project under example/ demonstrating @Model and @CubitState usage with ProductModel, AddressModel, ProductEntity, AddressEntity, ProductObject, AddressObject, and ProductState
1
likes
130
points
99
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A Dart code generator for Flutter boilerplate: model, entity, hive, and cubit state. Generates JSON serialization, copyWith, value equality, entity/Hive mapping, and pattern-matching extensions.

Homepage

License

MIT (license)

Dependencies

analyzer, build, flutter_boilerplate_annotations, glob, source_gen

More

Packages that depend on flutter_boilerplate_generator