whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>({
- TResult? android()?,
- TResult? ios()?,
- TResult? macos()?,
- TResult? web()?,
- TResult? linux()?,
- TResult? windows()?,
- TResult? fuchsia()?,
A variant of when
that fallback to returning null
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return null;
}
Implementation
@optionalTypeArgs
TResult? whenOrNull<TResult extends Object?>({
TResult? Function()? android,
TResult? Function()? ios,
TResult? Function()? macos,
TResult? Function()? web,
TResult? Function()? linux,
TResult? Function()? windows,
TResult? Function()? fuchsia,
}) {
final _that = this;
switch (_that) {
case AndroidPlatform() when android != null:
return android();
case IosPlatform() when ios != null:
return ios();
case MacosPlatform() when macos != null:
return macos();
case WebPlatform() when web != null:
return web();
case LinuxPlatform() when linux != null:
return linux();
case WindowsPlatform() when windows != null:
return windows();
case FuchsiaPlatform() when fuchsia != null:
return fuchsia();
case _:
return null;
}
}