back<T> method

void back<T>({
  1. T? result,
  2. bool closeOverlays = false,
  3. bool canPop = true,
  4. int? id,
})

Navigation.popUntil() shortcut.

Pop the current page, snackbar, dialog or bottomsheet in the stack

if your set closeOverlays to true, Get.back() will close the currently open snackbar/dialog/bottomsheet AND the current page

id is for when you are using nested navigation, as explained in documentation

It has the advantage of not needing context, so you can call from your business logic.

Implementation

void back<T>({
  T? result,
  bool closeOverlays = false,
  bool canPop = true,
  int? id,
}) {
  //TODO: This code brings compatibility of the new snackbar with GetX 4,
  // remove this code in version 5
  if (isSnackbarOpen && !closeOverlays) {
    closeCurrentSnackbar();
    return;
  }

  if (closeOverlays && isOverlaysOpen) {
    //TODO: This code brings compatibility of the new snackbar with GetX 4,
    // remove this code in version 5
    if (isSnackbarOpen) {
      closeAllSnackbars();
    }
    navigator?.popUntil((route) {
      return (!isDialogOpen! && !isBottomSheetOpen!);
    });
  }
  if (canPop) {
    if (global(id).currentState?.canPop() == true) {
      global(id).currentState?.pop<T>(result);
    }
  } else {
    global(id).currentState?.pop<T>(result);
  }
}