hide method

void hide([
  1. UniqueKey? key
])

Hides a specific dialog or the most recently shown dialog.

Implementation

void hide([UniqueKey? key]) {
  try {
    if (isActive) {
      _DialogEntry entry =
          key != null
              ? _dialogsStack.firstWhere(
                (element) => element.key == key,
                orElse: () => throw CustomException(
                  message: 'Dialog key not found.',
                ),
              )
              : _dialogsStack.last;
      _dialogsStack.remove(entry);
      entry.overlayEntry?.remove();
      entry.overlayEntry?.dispose();
    }
  } on CustomException {
    rethrow;
  } catch (e, s) {
    throw CustomException(
      message: 'An error occurred while hiding the dialog.',
      hiddenMessage: '{\ne: $e\ns:$s\n}',
    );
  }
}