showSnackBar method

void showSnackBar({
  1. required String text,
  2. TextStyle? textStyle,
  3. Duration? duration,
  4. Color? color,
  5. SnackBarAction? action,
  6. SnackBarBehavior behavior = SnackBarBehavior.fixed,
  7. Animation<double>? animation,
  8. VoidCallback? onVisible,
})

Show a SnackBar with text (maximum 2 lines) and color in the background. It will stayed for duration and automatically hides.

If action is true, a button will appear. The SnackBar will immediately hide on pressed.

Implementation

void showSnackBar({
  required String text,
  TextStyle? textStyle,
  Duration? duration,
  Color? color,
  SnackBarAction? action,
  SnackBarBehavior behavior = SnackBarBehavior.fixed,
  Animation<double>? animation,
  VoidCallback? onVisible,
}) {
  hideAll();
  final snackBar = SnackBar(
    content: Text(
      text,
      maxLines: customTheme.maxLines,
      overflow: TextOverflow.ellipsis,
      style: textStyle ?? customTheme.textStyle,
    ),
    backgroundColor: color,
    duration: duration ?? customTheme.defaultDuration,
    behavior: behavior,
    animation: animation,
    onVisible: onVisible,
    action: action == null
        ? customTheme.showDefaultAction
            ? SnackBarAction(
                label: "CLEAR",
                onPressed: hideAll,
              )
            : null
        : action,
  );
  showRawSnackBar(snackBar);
}