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()? initial,TResult? Function( int currentIndex)? loading,TResult? Function( int currentIndex, String currentItemId, Map<String, Player> players, Map<String, VideoController> controllers, List<MkVideoItem<T>> items, bool isPlaying, bool isMuted, bool isExpanded)? ready,TResult? Function( String message)? error,}) {final _that = this;
switch (_that) {
case _MkInitial() when initial != null:
return initial();case _MkLoading() when loading != null:
return loading(_that.currentIndex);case _MkReady() when ready != null:
return ready(_that.currentIndex,_that.currentItemId,_that.players,_that.controllers,_that.items,_that.isPlaying,_that.isMuted,_that.isExpanded);case _MkError() when error != null:
return error(_that.message);case _:
return null;
}
}