whenOrNull<TResult extends Object?> method
TResult?
whenOrNull<TResult extends Object?>({
- TResult? root()?,
- TResult? module()?,
- TResult? folder()?,
- TResult? component()?,
- TResult? documentation()?,
- TResult? story()?,
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 level, int index, String id, String title, bool isExpanded)?
root,
TResult? Function(
int level, int index, String id, String title, bool isExpanded)?
module,
TResult? Function(
int level, int index, String id, String title, bool isExpanded)?
folder,
TResult? Function(int level, int index, String id, String title,
bool isExpanded, Component component)?
component,
TResult? Function(int level, int index, String id, String title,
bool isExpanded, Component component, DocumentEntry document)?
documentation,
TResult? Function(int level, int index, String id, String title,
bool isExpanded, Component component, Story story)?
story,
}) {
final _that = this;
switch (_that) {
case RootNode() when root != null:
return root(
_that.level, _that.index, _that.id, _that.title, _that.isExpanded);
case ModuleNode() when module != null:
return module(
_that.level, _that.index, _that.id, _that.title, _that.isExpanded);
case FolderNode() when folder != null:
return folder(
_that.level, _that.index, _that.id, _that.title, _that.isExpanded);
case ComponentNode() when component != null:
return component(_that.level, _that.index, _that.id, _that.title,
_that.isExpanded, _that.component);
case DocumentationNode() when documentation != null:
return documentation(_that.level, _that.index, _that.id, _that.title,
_that.isExpanded, _that.component, _that.document);
case StoryNode() when story != null:
return story(_that.level, _that.index, _that.id, _that.title,
_that.isExpanded, _that.component, _that.story);
case _:
return null;
}
}