whenOrNull<R extends Object?> method

R? whenOrNull<R extends Object?>({
  1. R showLoading()?,
  2. R showContent(
    1. List<FormViewModel> viewModels,
    2. bool showNonEditableFields
    )?,
  3. R orElse(
    1. EditFormUIState editFormUIState
    )?,
})

Implementation

R? whenOrNull<R extends Object?>({
  R Function()? showLoading,
  R Function(List<FormViewModel> viewModels, bool showNonEditableFields)?
      showContent,
  R Function(EditFormUIState editFormUIState)? orElse,
}) {
  final editFormUIState = this;
  if (editFormUIState is EditFormUIStateShowLoading) {
    return showLoading != null
        ? showLoading()
        : orElse?.call(editFormUIState);
  } else if (editFormUIState is EditFormUIStateShowContent) {
    return showContent != null
        ? showContent(
            editFormUIState.viewModels, editFormUIState.showNonEditableFields)
        : orElse?.call(editFormUIState);
  } else {
    throw AssertionError();
  }
}