preferences_generator 3.0.1
preferences_generator: ^3.0.1 copied to clipboard
A powerful code generator that creates type-safe, boilerplate-free preference modules from simple abstract classes, used with `preferences_annotation`.
3.0.0 #
๐ฅ Breaking Changes #
- Requires:
preferences_annotation ^3.0.0. - Removed:
ResolvedMethodConfig,UnresolvedMethodConfig, andMethodConfiginternal model classes. All resolved method configurations are nowString?(null = disabled, non-null = final method name). Code that imported these internal classes will need to be updated. - Renamed: The
.testing()preset is now.exhaustive()in both the annotation and the generator. Any@PrefsModule.testing()usage will need updating.
๐ Bug Fixes #
- Fixed: Synchronous setters and removers now reference the generated keys
class (e.g.,
_AppSettingsKeys.username) in all adapter calls instead of raw string literals. This was a critical inconsistency โ_load()already used the keys class, but write methods did not. - Fixed: Generated local variable names in
_load()were usingALLCAPSsuffixes (e.g.,rawValueForUSERNAME). They now use proper camelCase (e.g.,rawUsername,newUsername). - Fixed: The internal change-tracking variable in
_load()was namedP_changed. It is now namedhasChanged. - Fixed: Double slash in
app_example/build.yaml(lib/generated/{{path}}//{{file}}.prefs.dartโlib/generated/{{path}}/{{file}}.prefs.dart).
๐ New Features #
- Added:
_isLoadedguard in the generated_load()method. The first call populates the in-memory cache from storage; subsequent calls are no-ops.refresh()resets the flag before re-reading. This prevents N full storage reads when N async getters are called in sequence and eliminates the possibility of inconsistent interim state. - Added: Build-time template validation. Per-entry template overrides in
@PrefEntryand module-level templates in@PrefsModuleare now validated to contain at least one{{name}}or{{Name}}token. A clearInvalidGenerationSourceErroris thrown if a bare literal name is provided where a template is required. - Added: Error handling in fire-and-forget sync writes. All
Future(() async { ... })write blocks now include a try/catch. If@PrefsModule(onWriteError: ...)is provided, the callback is invoked on failure; otherwise the error is silently discarded. - Added:
ExceptionHandler.invalidEntryTemplate()โ clear build error for per-entry templates missing substitution tokens. - Added:
ExceptionHandler.invalidModuleTemplate()โ clear build error for module-level templates missing substitution tokens.
โฌ๏ธ Dependency Updates #
- Updated:
analyzerfrom^9.0.0to^10.0.0. - Updated:
preferences_annotationfrom^2.0.0to^3.0.0.
๐งช Tests #
- Added: Golden file test for the
.reactive()preset โ full pipeline output snapshot intest/src/golden/reactive_preset_test.dart. - Added: Golden file test for the
.minimal()preset โ verifies no async, stream, or module-level methods are emitted. - Rewritten:
method_namer_test.dartโ fully updated for the newMethodNamer.resolve(template, entryName)andMethodNamer.hasToken(template)API. - Updated:
value_change_logic_builder_test.dartโ mocks updated forString?resolved method names; new assertions for keys class references and error handling. - Updated:
mixin_writer_test.dartโ mocks updated forString?resolved method names; new assertion for_isLoadedreset inrefresh()andremoveAll().
2.0.7 #
๐ง Maintenance #
- Updated: Minimum Dart SDK constraint raised from
^3.9.0to^3.10.0. - Updated:
analyzerdependency upgraded from^9.0.0to^10.0.0.
2.0.3 #
๐ Bug Fixes #
- Fixed: Resolved a critical crash that occurred when a user customised
build_extensionsin theirbuild.yaml.
2.0.2 #
๐ง Improvements & Maintenance #
- Improved: Simplified the builder configuration for end-users.
- Refactored: Internal builder factory renamed to
preferences.
2.0.1 #
๐ Documentation #
- Improved: Overhauled the
README.mdwith comprehensive configuration documentation.
2.0.0 #
- Initial major release with schema-in-constructor API, presets, automatic
serialization, stream generation, and global
build.yamlconfiguration.
๐ Features #
- Added: Schema-in-Constructor API. Preference schemas are now defined in a private,
generative constructor (e.g.,
MySettings._({...})) instead of a factory. This enables the use of standard Dart default values. - Added:
@PrefsModulePresets. Introduced powerful presets like.dictionary(),.syncOnly(), and.reactive()to quickly configure the generated API to match common storage backend patterns. - Added: Automatic Serialization. The generator now automatically handles the serialization
of complex types (
DateTime,Duration,Enum,Record, and custom types viaPrefConverter). ThePrefsAdapteris now only responsible for handling primitive types. - Added:
StreamGeneration. Added the ability to generate reactiveStreams for any preference entry via the.reactive()preset or a customstreamerconfiguration. - Added: Global
build.yamlConfiguration. You can now define project-wide settings, such askey_case: snake, to enforce conventions across all preference modules. - Added:
KeyCaseConvention. Introduced thekeyCaseproperty in@PrefsModuleandbuild.yamlto automatically transform generated storage keys tosnake_case,kebab-case, etc. - Added: Custom
PrefConverterSupport. Added theconverterproperty to@PrefEntryto allow users to provide a reusable class for serializing and deserializing complex custom types. - Added: Fine-Grained Method Configuration. Introduced
CustomConfig,AffixConfig, andNamedConfigobjects to allow precise control over every generated method's name and behavior, including enabling/disabling individual methods.
๐ฅ Breaking Changes #
- Refactored: The schema definition has moved from a
factoryconstructor to a private generative constructor. The old factory-based schema is no longer supported. - Changed: The default generated file extension has changed from
.g.dartto.prefs.dart. Allpartdirectives must be updated. - Renamed: The
PreferenceAdapterinterface has been renamed toPrefsAdapter. - Simplified: The contract for
PrefsAdapterhas been radically simplified. It is now only required to handle primitives (String,int,double,bool,List<String>). All manual serialization logic for complex types must be removed from adapter implementations. - Removed: The
containsKey()method has been removed from the adapter interface. - Renamed: The
clear()method in the adapter interface has been renamed toremoveAll(). - Changed: The
@PreferenceEntry(defaultValue: ...)property has been removed. Default values must now be provided using standard Dart syntax in the schema constructor (e.g.,String username = 'guest'). - Changed: Generated method names are now more explicit and configurable. A field named
themewill now generate methods likegetTheme()andsetTheme(...)instead of a top-leveltheme - getter/setter pair.
๐ Bug Fixes & Improvements #
- Improved: Code generation for collection literals (
const [],const {}) now automatically infers and adds the correct type arguments to prevent type errors in the generated code. - Improved: The entire generator codebase has been refactored into a more robust and testable architecture, separating analysis, model-building, and code generation into distinct, decoupled phases.
- Improved: Error messages are now more consistent and are all centralized in a dedicated
ExceptionHandlerclass. - Fixed: Resolved several bugs related to nullable type handling in setters and deserialization logic.
1.1.4 #
- Maintained: Downgraded
source_gento be compatible with other packages.
1.1.3 #
- Maintained: Downgraded
buildto be compatible with other packages.
1.1.2 #
- Updated: Updated dependencies to their latest releases.
- Refactored: Removed deprecated code.
1.1.1 #
- Docs: Enhanced documentation clarity.
1.1.0 #
- Docs: Enhanced description clarity.
- Refactored: Removed support for non
dart:coredata typeColor. - Added: Added support for
SetandDuration. - Style: Refined code formatting.
1.0.0 #
- Added: Initial release of
preferences_generator. - Added: Implemented code generation for classes annotated with
@PreferenceModule. - Added: Added support for
int,String,double,bool,DateTime,Color,List,Map,Enum, andRecordtypes. - Added: Implemented robust error handling for common misconfigurations.