How to forcefully close GetX Snackbar?
Use Get.back() to close the snack bar.
If you want the user to close snack bar, You can use Get.back
either in mainButton or onTap
Get.snackbar(
"Requesting very important data...",
"",
duration: 60.seconds, // it could be any reasonable time, but I set it lo-o-ong
snackPosition: SnackPosition.BOTTOM,
showProgressIndicator: true,
isDismissible: true,
backgroundColor: Colors.lightGreen,
colorText: Colors.white,
mainButton: TextButton(
onPressed: Get.back,
child: const Text(
"Close"
)));
);
If debugLocked issue arise on close, use SchedulerBinding
SchedulerBinding.instance!.addPostFrameCallback((_) {
// Your Get Snackbar
}):
GetX has already a method called closeAllSnackbars()
and closeCurrentSnackbar()
.
So use closeAllSnackbars()
to close all open Snackbars.
Get.closeAllSnackbars();
And to close the current active snakbar simply call closeCurrentSnackbar()
.
Get.closeCurrentSnackbar();
You can also check weather the snackbar is open/active or not by calling isSnackbarOpen()
.
Get.isSnackbarOpen();
Use this method to close the current Snackbar immediately
ScaffoldMessenger.of(context).removeCurrentSnackBar();