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);

      final theme = Theme.of(context);

      ScaffoldMessenger.of(context).showSnackBar(
        SnackBar(
          behavior: SnackBarBehavior.fixed,
          backgroundColor: isSuccess
              ? const Color(0xFFECFDF3) // Light success green
              : const Color(0xFFFEF3F2), // Light error red
          duration: Duration(seconds: seconds),
          content: Text(
            title,
            style: TextStyle(
              color: isSuccess
                  ? const Color(0xFF027A48) // Dark success green
                  : const Color(0xFFB42318), // Dark error red
              fontSize: 13,
              fontWeight: FontWeight.w500,
              overflow: TextOverflow.ellipsis,
            ),
            maxLines: 10,
          ),
          action: action,
        ),
      );
    }
  });
}