back<T> method
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,
}) {
if (isSnackBarOpen && !closeOverlays) {
closeCurrentSnackBar();
return;
}
if (closeOverlays && isOverlaysOpen) {
if (isSnackBarOpen) {
closeCurrentSnackBar();
}
navigator?.popUntil((route) {
return (!isDialogOpen! && !isBottomSheetOpen!);
});
}
try {
if (canPop) {
if (key.currentState?.canPop() == true) {
pop<T>(result);
}
} else {
pop<T>(result);
}
} catch (error) {
if (routing.isDialog == true || routing.isBottomSheet == true) {
Navigator.pop<T>(key.currentContext!);
}
}
}