Skip to content

fix(platform_interface): restore copyWith() data preservation with shared unset sentinel - #201

Open
m-abs wants to merge 4 commits into
Notalib:mainfrom
m-abs:fix/copy-with-null
Open

fix(platform_interface): restore copyWith() data preservation with shared unset sentinel#201
m-abs wants to merge 4 commits into
Notalib:mainfrom
m-abs:fix/copy-with-null

Conversation

@m-abs

@m-abs m-abs commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

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

  1. Extract a single shared const unset sentinel into utils/constants.dart.
  2. Consolidate the repeated additional-properties merge logic into a
    copyAdditionalProperties() helper on AdditionalProperties.
  3. Update all model copyWith methods to use the a sentinel pattern and use the copyAdditionalProperties() helper.

Changes

  • 28 files changed, +1469 / -413
  • New: utils/constants.dart, AdditionalProperties.copyAdditionalProperties()
  • Updated: all model copyWith methods (Locator, Locations, Properties, Publication, etc.)
  • Added: comprehensive tests for each model's copyWith behavior

Verification

Tests added in test/models_test.dart cover copyWith() with no args (preserves all fields)
and selective overrides for each model. Run dart test in flutter_readium_platform_interface/.

m-abs added 2 commits August 11, 2026 19:28
…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.
@m-abs
m-abs requested a review from ddfreiling August 11, 2026 22:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants