Created
February 27, 2023 12:13
-
-
Save TatsuUkraine/06b1f96e4e9139265c82ef42b659163b to your computer and use it in GitHub Desktop.
null aware copywith
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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