mapOrNull<TResult extends Object?> method
- @optionalTypeArgs
- TResult? giftCode(
- ChatBoostSourceGiftCode value
- TResult? giveaway(
- ChatBoostSourceGiveaway 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(ChatBoostSourcePremium value)? premium,
TResult? Function(ChatBoostSourceGiftCode value)? giftCode,
TResult? Function(ChatBoostSourceGiveaway value)? giveaway,
}) {
final _that = this;
switch (_that) {
case ChatBoostSourcePremium() when premium != null:
return premium(_that);
case ChatBoostSourceGiftCode() when giftCode != null:
return giftCode(_that);
case ChatBoostSourceGiveaway() when giveaway != null:
return giveaway(_that);
case _:
return null;
}
}