I am implementing a redux store where I treat the store as immutable. Therefore the store looks something like this:
class State {
final String firstname;
final String lastname;
State(this.firstname, this.lastname);
State.initial()
: this.firstname = null,
this.lastname = null;
State copy({String firstname, String lastname}) =>
new State(firstname ?? this.firstname, lastname ?? this.lastname);
}
This all works fine and I can copy the State and replace individual fields within the copy.
state.copy(firstname: "foo");
but now I can't set a field back to null of course.
state.copy(firstname: null);
doesn't work.
I also tried something like:
State copy({String firstname = this.firstname, String lastname = this.lastname}) => ...
but Dart does not allow non const as default values.