Created
June 25, 2024 16:38
-
-
Save jezell/60c884b2db5dcb58a67851c87f809723 to your computer and use it in GitHub Desktop.
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
void main() { | |
print(fullName(null, null)); | |
print(fullName('John', null)); | |
print(fullName(null, 'Doe')); | |
print(fullName("John", 'Doe')); | |
} | |
String fullName( | |
String? firstName, | |
String? lastName, | |
) => | |
'${firstName.orDefault} ${lastName.orDefault}'; | |
extension DefaultValuesString on String? { | |
String get orDefault { | |
return this ?? ''; | |
} | |
} | |
extension DefaultValuesInt on int? { | |
int get orDefault { | |
return this ?? 0; | |
} | |
} | |
extension DefaultValuesDouble on double? { | |
double get orDefault { | |
return this ?? 0.0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment