whenOrElse<W> method
W
whenOrElse<W>({
- W loading()?,
- W loaded(
- D data
- W error(
- dynamic error,
- String message
- required W orElse(),
Pattern matching for state types, with a required fallback.
Returns the result of the matching callback, or orElse if no match is found.
loading: Optional callback for NotifierStateLoading.loaded: Optional callback for NotifierStateLoaded, provides the loaded data.error: Optional callback for NotifierStateError, provides the error and message.orElse: Required fallback callback if no match is found.
Implementation
W whenOrElse<W>({
W Function()? loading,
W Function(D data)? loaded,
W Function(dynamic error, String message)? error,
required W Function() orElse,
}) {
if (this is NotifierStateLoading) {
return loading?.call() ?? orElse();
} else if (this is NotifierStateLoaded) {
return loaded?.call((this as NotifierStateLoaded<T, D>).data) ?? orElse();
} else if (this is NotifierStateError) {
return error?.call(
(this as NotifierStateError).error,
(this as NotifierStateError).message,
) ??
orElse();
}
return orElse();
}