whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>({})
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( int receivedBytes)? inProgress,TResult? Function( Uint8List data, int totalBytes, bool crcValid)? completed,TResult? Function( String message, int? code, int? receivedBytes)? failed,TResult? Function()? idle,}) {final _that = this;
switch (_that) {
case FetchProgressInProgress() when inProgress != null:
return inProgress(_that.receivedBytes);case FetchProgressCompleted() when completed != null:
return completed(_that.data,_that.totalBytes,_that.crcValid);case FetchProgressFailed() when failed != null:
return failed(_that.message,_that.code,_that.receivedBytes);case FetchProgressIdle() when idle != null:
return idle();case _:
return null;
}
}