showToast function

void showToast(
  1. String message, {
  2. VoidCallback? callback,
})

Implementation

void showToast(String message, {VoidCallback? callback}) {
  if (Get.context != null) {
    ScaffoldMessenger.of(Get.context!)
        .showSnackBar(
          SnackBar(
            backgroundColor: Colors.white,
            content: WillPopScope(
              onWillPop: () async {
                ScaffoldMessenger.of(Get.context!).removeCurrentSnackBar();
                return true;
              },
              child: Text(
                message,
                style: const TextStyle(color: Colors.black),
              ),
            ),
            duration: const Duration(seconds: 2),
          ),
        )
        .closed
        .then((reason) {
      if (callback != null) {
        callback();
      }
    });
  }
}