0Pricing
Dart Academy · Lesson

copyWith and Value Equality

Update immutable data and compare by value.

Updating Immutable Data

You can not change an immutable object, so to update it you create a new one. The pattern that does this cleanly is copyWith.

What copyWith Does

A copyWith method returns a fresh object, keeping current values for fields you skip and replacing only the ones you pass.

final updated = user.copyWith(name: 'Ada');

All lessons in this course

  1. Final Fields and Deep Immutability
  2. sealed Classes and Exhaustive switch
  3. base, interface, and final Modifiers
  4. copyWith and Value Equality
← Back to Dart Academy