backLegacy<T> method

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

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 backLegacy<T>({
  T? result,
  bool closeOverlays = false,
  bool canPop = true,
  int times = 1,
  String? id,
}) {
  if (closeOverlays) {
    closeAllOverlays();
  }

  if (times < 1) {
    times = 1;
  }

  if (times > 1) {
    int count = 0;
    return searchDelegate(id)
        .navigatorKey
        .currentState
        ?.popUntil((Route route) {
      return count++ == times;
    });
  } else {
    if (canPop) {
      if (searchDelegate(id).navigatorKey.currentState?.canPop() == true) {
        return searchDelegate(id).navigatorKey.currentState?.pop<T>(result);
      }
    } else {
      return searchDelegate(id).navigatorKey.currentState?.pop<T>(result);
    }
  }
}