maybeWhen<TResult extends Object?> method
TResult
maybeWhen<TResult extends Object?>({
- TResult root()?,
- TResult module()?,
- TResult folder()?,
- TResult component()?,
- TResult documentation()?,
- TResult story()?,
- required TResult orElse(),
A variant of when
that fallback to an orElse
callback.
It is equivalent to doing:
switch (sealedClass) {
case Subclass(:final field):
return ...;
case _:
return orElse();
}
Implementation
@optionalTypeArgs
TResult maybeWhen<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,
required TResult orElse(),
}) {
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 orElse();
}
}