Skip to content

Instantly share code, notes, and snippets.

@jezell
Created June 25, 2024 16:38
Show Gist options
  • Save jezell/60c884b2db5dcb58a67851c87f809723 to your computer and use it in GitHub Desktop.
Save jezell/60c884b2db5dcb58a67851c87f809723 to your computer and use it in GitHub Desktop.
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