fix(platform_interface): restore copyWith() data preservation with shared unset sentinel - #201
Open
m-abs wants to merge 4 commits into
Open
fix(platform_interface): restore copyWith() data preservation with shared unset sentinel#201m-abs wants to merge 4 commits into
m-abs wants to merge 4 commits into
Conversation
…nset sentinel pattern The conversion from null-coalescing (??) to _unset sentinel pattern incompletely updated 24 copyWith methods across the platform interface. Parameters retained original nullable types (e.g., double? position) which default to null, causing identical(null, _unset) to return false and silently zeroing all fields when copyWith() is called with no args. Fixed by converting all parameters to Object? = _unset and updating body casts to (param as ActualType)!. Removed dead _UnsetSentinel class from locator.dart that was no longer referenced. All 103 tests pass after this fix.
…dditionalProperties helper Replace per-class `static const _unset = Object()` declarations with a single shared `const unset` in utils/constants.dart. Consolidate the repeated additional-properties merge logic into a `copyAdditionalProperties` helper on AdditionalProperties. Update all model copyWith methods to use the shared constant and helper, and add tests for each.
ddfreiling
approved these changes
Aug 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
copyWith()methods didn't allow you to null properties because of null checks on the input value would result in the original value being copy.Solution
const unsetsentinel intoutils/constants.dart.copyAdditionalProperties()helper onAdditionalProperties.copyWithmethods to use the a sentinel pattern and use thecopyAdditionalProperties()helper.Changes
utils/constants.dart,AdditionalProperties.copyAdditionalProperties()copyWithmethods (Locator, Locations, Properties, Publication, etc.)copyWithbehaviorVerification
Tests added in
test/models_test.dartcovercopyWith()with no args (preserves all fields)and selective overrides for each model. Run
dart testinflutter_readium_platform_interface/.