snackBar function

void snackBar(
  1. BuildContext context,
  2. {String title = '',
  3. Widget? content,
  4. SnackBarAction? snackBarAction,
  5. Function? onVisible,
  6. Color? textColor,
  7. Color? backgroundColor,
  8. EdgeInsets? margin,
  9. EdgeInsets? padding,
  10. Animation<double>? animation,
  11. double? width,
  12. ShapeBorder? shape,
  13. Duration? duration,
  14. SnackBarBehavior? behavior,
  15. double? elevation}
)

Show SnackBar

Implementation

void snackBar(
  BuildContext context, {
  String title = '',
  Widget? content,
  SnackBarAction? snackBarAction,
  Function? onVisible,
  Color? textColor,
  Color? backgroundColor,
  EdgeInsets? margin,
  EdgeInsets? padding,
  Animation<double>? animation,
  double? width,
  ShapeBorder? shape,
  Duration? duration,
  SnackBarBehavior? behavior,
  double? elevation,
}) {
  if (title.isEmpty && content == null) {
    log('SnackBar message is empty');
  } else {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(
        backgroundColor: backgroundColor,
        action: snackBarAction,
        margin: margin,
        animation: animation,
        width: width,
        shape: shape,
        duration: duration ?? 4.seconds,
        behavior: margin != null ? SnackBarBehavior.floating : behavior,
        elevation: elevation,
        onVisible: onVisible?.call(),
        content: content ??
            Padding(
              padding: padding ?? EdgeInsets.symmetric(vertical: 4),
              child: Text(
                title,
                style: primaryTextStyle(color: textColor ?? Colors.white),
              ),
            ),
      ),
    );
  }
}