class Foo {
final int? i;
Foo({this.i});
Foo copyWith({int? x}) {
return Foo(i: x ?? i);
}
}
void main() {
final foo = Foo(i: 0);
foo.copyWith(x: null);
print(foo.i); // prints `0` but should print `null`.
}
How can I actually pass null
value to the method? In earlier Dart version copyWith()
and copyWith(x: null)
were two different things.
Note: I'm not looking for workarounds like making a new variable, like isNull
and then deciding whether to pass null
or not based on its value.