mutate method

void mutate(
  1. void mutator(
    1. T value
    )
)

Mutates the current value in place and forces a notification.

This method is designed for mutable objects (models, lists, maps, etc.) where modifying the instance does not change the reference.

Unlike set or update, mutate always triggers a notification even if the underlying object reference stays the same.

Use this when you intentionally modify the existing value instead of creating a new instance.

Example:

user.mutate((u) {
  u.name = "Max";
  u.age++;
});

⚠️ Note:

  • Prefer immutable objects when possible
  • Use mutate only when in-place mutation is required

Implementation

void mutate(void Function(T value) mutator) {
  mutator(_value);
  notify();
}