snackBarContent function

SnackBar snackBarContent({
  1. required BuildContext context,
  2. required String title,
  3. required String message,
  4. Color backgroundColor = Colors.black,
  5. Icon icon = const Icon(Icons.check_circle, color: Colors.amber, size: 28),
  6. Color closeButtonColor = Colors.amber,
  7. Color arrowBackgroundColor = Colors.white,
  8. int? seconds,
})

Create the snackbar content

Implementation

SnackBar snackBarContent({
  required BuildContext context,
  required String title,
  required String message,
  Color backgroundColor = Colors.black,
  Icon icon = const Icon(Icons.check_circle, color: Colors.amber, size: 28),
  Color closeButtonColor = Colors.amber,
  Color arrowBackgroundColor = Colors.white,
  int? seconds,
}) {
  Widget content = Stack(
    clipBehavior: Clip.none,
    children: [
      Container(
        margin: const EdgeInsets.only(top: 20),
        decoration: BoxDecoration(
          color: backgroundColor,
          borderRadius: BorderRadius.circular(10),
        ),
        child: Row(crossAxisAlignment: CrossAxisAlignment.center, children: [
          const SizedBox(
            width: 16,
          ),
          Expanded(
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                const SizedBox(height: 24),
                Text(
                  title,
                  style: const TextStyle(
                      color: Colors.white,
                      fontSize: 14,
                      fontWeight: FontWeight.bold),
                ),
                const SizedBox(height: 8),
                Text(
                  message,
                  style: const TextStyle(color: Colors.white, fontSize: 13),
                ),
                const SizedBox(height: 16),
              ],
            ),
          ),
          IconButton(
            onPressed: () {
              ScaffoldMessenger.of(context).hideCurrentSnackBar();
            },
            icon: Icon(
              Icons.close,
              color: closeButtonColor,
            ),
          ),
        ]),
      ),
      Positioned(
        left: 16,
        top: -8,
        child: CustomPaint(
          painter: CustomStyleArrow(color: arrowBackgroundColor),
          child: Container(
            padding: const EdgeInsets.all(4),
            child: icon,
          ),
        ),
      ),
    ],
  );

  return SnackBar(
    backgroundColor: Colors.transparent,
    behavior: SnackBarBehavior.floating,
    elevation: 0,
    duration: Duration(seconds: seconds ?? 10),
    content: content,
  );
}