mapOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? fill(
- BackgroundTypeFill value
- TResult? wallpaper(
- BackgroundTypeWallpaper value
- TResult? pattern(
- BackgroundTypePattern value
- TResult? chatTheme(
- BackgroundTypeChatTheme value
A variant of map that fallback to returning null.
It is equivalent to doing:
switch (sealedClass) {
case final Subclass value:
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs
TResult? mapOrNull<TResult extends Object?>({
TResult? Function(BackgroundTypeFill value)? fill,
TResult? Function(BackgroundTypeWallpaper value)? wallpaper,
TResult? Function(BackgroundTypePattern value)? pattern,
TResult? Function(BackgroundTypeChatTheme value)? chatTheme,
}) {
final _that = this;
switch (_that) {
case BackgroundTypeFill() when fill != null:
return fill(_that);
case BackgroundTypeWallpaper() when wallpaper != null:
return wallpaper(_that);
case BackgroundTypePattern() when pattern != null:
return pattern(_that);
case BackgroundTypeChatTheme() when chatTheme != null:
return chatTheme(_that);
case _:
return null;
}
}