flutter_boilerplate_generator 2.3.0
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: newDependencyInjectionBuilderthat scans all Dart source files for classes annotated with@Injectable,@Singleton,@LazySingleton,@Module, and@Named, then generates a singleinject.config.dartfile exposing aconfigureDependencies()function that registers every discovered dependency in topological order.build.yaml: registereddependency_injection_buildertargeting$package$sobuild_runnerpicks it up automatically without consumer configuration.builder.dart: exported the newdependencyInjectionBuilderfactory alongside the existing model and state builders.- Example under
example/lib/di/demonstrating real-world DI wiring:ApiClient,AppConfig,GetUserUseCase,NetworkModule,UserDataSource,UserRepository, andmain.dartcalling the generatedconfigureDependencies()on startup.
2.2.0 - 2026-06-22 #
Fixed #
state_generator.dart: generator no longer crashes when a@CubitStateclass contains static members or other non-factory child elements — only factory constructors are processed.copy_with_helper.dart:nonDartTypeCopyWithno longer generates a nestedcopyWithfor 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-timeInvalidGenerationSourceErroris 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:fromJsonforList<XModel>fields now casts to a bareListbefore mapping, avoiding aTypeErrorcaused by castingList<dynamic>to a typedList<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:toJsonforDateTimefields now emits.toIso8601String()instead of the raw object, matching thefromJsoncounterpart that callsDateTime.parse(...).json_helper.dart:toJsonforDurationfields now emits.inMicrosecondsinstead of the raw object, matching thefromJsoncounterpart that callsDuration(microseconds: ...).json_helper.dart:toJsonfor a single nested model field (notList, notMap, not enum, not a scalar primitive) now calls.toJson()on the nested instance, preventingjsonEncodefrom 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()andfromEntitycounterpart — previously treated as a primitive pass-through.entity_helper.dart: nullable entity field passed tofromEntitynow 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 duplicateconst _sentinel = Object()— sentinel constant is now named per-class (e.g._$MessageDtoSentinel).copy_with_helper.dart:nonDartTypeCopyWithno longer generates nested copyWith classes that reference transitive types not imported by the consumer file — classes withList<XModel>or other non-resolvable nested types are now skipped via a recursive_isFullyResolvablecheck.model_generator.dart: two or more fields sharing the same non-primitive type no longer produce duplicate_$XCopyWithclass declarations — generation is deduped by type name.model_generator.dart: non-null constructor parameters now correctly emit therequiredkeyword in the generated_ClassNameimplementation.json_helper.dart:fromJsonno longer wraps non-null fields (no@Default) in a null check that returnsnull— the parsed value is used directly, matching therequiredconstructor param.json_helper.dart:toJsonforList<XModel>fields now calls.map((e) => e.toJson()).toList()instead of serialising the raw object.hive_helper.dart:toHiveObjectandfromHiveObjectnow handleList<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 importpackage:flutter_boilerplate_annotations/flutter_boilerplate_annotations.dartdirectly.
Added #
flutter_boilerplate_annotationsadded as a pub.dev dependency to supply annotation classes previously bundled in this package.
Fixed #
field_meta_helper.dart: correctedinPackageonTypeCheckerforJsonKeyandDefaultfrom'core'to'flutter_boilerplate_annotations', so element-based annotation detection now works correctly.build,source_gen, andanalyzermoved fromdev_dependenciestodependencies— they are imported directly by library code inlib/and are runtime dependencies of the generator.
Changed #
- Removed unused imports of
package:flutter_boilerplate_generator/flutter_boilerplate_generator.dartfrom example files; annotations are now imported directly fromflutter_boilerplate_annotations.
1.0.0 - 2026-06-19 #
Added #
ModelGenerator: generatesfromJson,toJson,copyWith,==, andhashCodefor classes annotated with@ModelStateGenerator: generatescopyWith,==, andhashCodefor classes annotated with@CubitState- Code generation helpers:
entity_helper.dart— generates entity mapping from model fieldsjson_helper.dart— generatesfromJson/toJsonmethodshive_helper.dart— generates Hive object mappingcopy_with_helper.dart— generatescopyWithmethodcompareable_helper.dart— generates==andhashCodefield_meta_helper.dart— extracts field metadata from analyzer elementstype_helper.dart— resolves Dart type names for code generation
build.yamlconfiguration wiringModelBuilderandStateBuildertobuild_runner- Example project under
example/demonstrating@Modeland@CubitStateusage withProductModel,AddressModel,ProductEntity,AddressEntity,ProductObject,AddressObject, andProductState