showSnackBar function

void showSnackBar({
  1. String title = "",
  2. bool isSuccess = false,
  3. SnackBarAction? action,
  4. int seconds = 1,
})

Implementation

void showSnackBar({String title = "", bool isSuccess = false, SnackBarAction? action, int seconds = 1,}) {
  WidgetsBinding.instance.addPostFrameCallback((_) {
    final context = navigatorKeyTry.currentContext;
    if (context != null) {
      removeCurrentSnackBar(context);
      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          behavior: SnackBarBehavior.fixed,
          backgroundColor: isSuccess
              ? ColorConstants.successBgSnackBarColor
              : ColorConstants.errorBgSnackBarColor,
          duration: Duration(seconds: seconds),
          content: Text(
            title,
            style: TextStyle(
              color: isSuccess
                  ? ColorConstants.successTextSnackBarColor
                  : ColorConstants.errorTextSnackBarColor,
              fontSize: 13,
              fontWeight: FontWeight.w500,
              overflow: TextOverflow.ellipsis,
            ),
            maxLines: 10,
          ),
          action: action,
        ),
      );
    }
  });
}