Skip to content

Instantly share code, notes, and snippets.

@TatsuUkraine
Created February 27, 2023 12:13
Show Gist options
  • Save TatsuUkraine/06b1f96e4e9139265c82ef42b659163b to your computer and use it in GitHub Desktop.
Save TatsuUkraine/06b1f96e4e9139265c82ef42b659163b to your computer and use it in GitHub Desktop.
null aware copywith
class SomeThing {
final String value1;
final String? value2;
SomeThing({
this.value1 = 'first value',
this.value2,
});
SomeThing copyWith({
String? value1,
String? value2,
}) => SomeThing(
value1: value1 ?? this.value1,
value2: value2 ?? this.value2,
);
}
void main() {
SomeThing someThing = SomeThing(value2: 'second value');
someThing = someThing.copyWith(value2: null);
print(someThing.value2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment