D
State ManagementIntermediate30 XP3 min read

What is the difference between mutable ChangeNotifier and immutable state?

TL;DR: ChangeNotifier holds mutable state and calls notifyListeners(). Immutable state (e.g., with freezed) creates new state objects on change — enabling value equality, easier debugging, and predictable rebuilds.

Full Answer

AspectMutable ChangeNotifierImmutable State
State mutationsMutate fields in-placeCreate new state objects (copyWith)
EqualityReference equality — hard to detect field changesValue equality — == compares all fields
DebuggingHard to trace what changedEach emission is a snapshot — easy to diff
Rebuild controlnotifyListeners() rebuilds all listenersEquality checks skip unnecessary rebuilds
BoilerplateLowHigher (use freezed/equatable to reduce it)
🎯

Use the freezed package to generate copyWith, ==, hashCode, and toString for immutable state classes automatically.

Code Examples

dartImmutable state with freezed
Output
current.isLoading == false; updated.isLoading == true; current == updated → false

Common Mistakes

  • Mutating a list inside ChangeNotifier without calling notifyListeners()
  • Comparing ChangeNotifier instances with == expecting value equality

Interview Tip

💡

Mentioning freezed as a code-generation tool for immutable state shows you're aware of Dart's ecosystem beyond the standard library.

#ChangeNotifier#immutable#state#equatable#freezed