showSnackbar static method

dynamic showSnackbar(
  1. String message, {
  2. bool top = false,
  3. Color? backgroundColor,
  4. TextStyle? style,
  5. double? elevation,
  6. EdgeInsetsGeometry? margin,
  7. EdgeInsetsGeometry? padding,
  8. double? width,
  9. ShapeBorder? shape,
  10. HitTestBehavior? hitTestBehavior,
  11. SnackBarBehavior? behavior,
  12. SnackBarAction? action,
  13. double? actionOverflowThreshold,
  14. bool? showCloseIcon,
  15. Color? closeIconColor,
  16. Duration duration = _snackBarDisplayDuration,
  17. Animation<double>? animation,
  18. void onVisible()?,
  19. Widget? leading,
  20. DismissDirection? dismissDirection,
  21. Clip clipBehavior = Clip.hardEdge,
})

muestra mensaje recibe message, backgroundColor Recibe el color que se mostrara style Puede ser nulo y pode defecto toma un valor top Permite eligir si mostrara el mensaje en la parte superior o inferior por defecto es false

Implementation

static showSnackbar(
  String message, {
  bool top = false,
  Color? backgroundColor,
  TextStyle? style,
  double? elevation,
  EdgeInsetsGeometry? margin,
  EdgeInsetsGeometry? padding,
  double? width,
  ShapeBorder? shape,
  HitTestBehavior? hitTestBehavior,
  SnackBarBehavior? behavior,
  SnackBarAction? action,
  double? actionOverflowThreshold,
  bool? showCloseIcon,
  Color? closeIconColor,
  Duration duration = _snackBarDisplayDuration,
  Animation<double>? animation,
  void Function()? onVisible,
  Widget? leading,
  DismissDirection? dismissDirection,
  Clip clipBehavior = Clip.hardEdge,
}) async {
  top
      ? messagerKey.currentState!.clearMaterialBanners()
      : messagerKey.currentState!.clearSnackBars();
  final snackbar = Text(
    message,
    style: style ?? const TextStyle(color: Colors.white, fontSize: 15),
  );

  /// Mostrara el mensaje en la parte superior
  if (top) {
    messagerKey.currentState!.showMaterialBanner(MaterialBanner(
        animation: animation,
        contentTextStyle: style,
        leading: leading,
        elevation: elevation,
        margin: margin,
        onVisible: onVisible,
        padding: padding,
        backgroundColor: backgroundColor ?? const Color(0xFF323232),
        content: snackbar,
        actions: const [
          SizedBox(),
        ]));
    await Future.delayed(const Duration(milliseconds: 3000))
        .then((value) => messagerKey.currentState!.clearMaterialBanners());
  } else {
    messagerKey.currentState!.showSnackBar(SnackBar(
      content: snackbar,
      backgroundColor: backgroundColor,
      action: action,
      actionOverflowThreshold: actionOverflowThreshold,
      animation: animation,
      behavior: behavior ?? SnackBarBehavior.floating,
      clipBehavior: clipBehavior,
      closeIconColor: backgroundColor,
      dismissDirection: dismissDirection ?? DismissDirection.down,
      duration: duration,
      elevation: elevation,
      hitTestBehavior: hitTestBehavior,
      margin: margin,
      onVisible: onVisible,
      padding: padding,
      shape: shape ?? _validShape(behavior),
      showCloseIcon: showCloseIcon,
      width: width,
    ));
  }
}