show static method

void show(
  1. BuildContext context, {
  2. required String message,
  3. Color backgroundColor = const Color(0xE6000000),
  4. Color textColor = Colors.white,
  5. TextStyle? textStyle,
  6. IconData? icon,
  7. double? iconSize,
  8. Duration duration = const Duration(seconds: 2),
  9. EdgeInsets margin = const EdgeInsets.symmetric(horizontal: 24, vertical: 64),
  10. EdgeInsetsGeometry padding = const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
  11. double radius = 12.0,
  12. double elevation = 2.0,
  13. Color? shadowColor,
  14. Color? borderColor,
  15. double borderWidth = 1.0,
  16. bool top = false,
  17. int maxLines = 4,
  18. TextOverflow overflow = TextOverflow.ellipsis,
})

Base overlay toast.

Implementation

static void show(
  BuildContext context, {
  required String message,
  Color backgroundColor = const Color(0xE6000000),
  Color textColor = Colors.white,
  TextStyle? textStyle,
  IconData? icon,
  double? iconSize,
  Duration duration = const Duration(seconds: 2),
  EdgeInsets margin = const EdgeInsets.symmetric(
    horizontal: 24,
    vertical: 64,
  ),
  EdgeInsetsGeometry padding = const EdgeInsets.symmetric(
    horizontal: 16,
    vertical: 12,
  ),
  double radius = 12.0,
  double elevation = 2.0,
  Color? shadowColor,
  Color? borderColor,
  double borderWidth = 1.0,
  bool top = false,
  int maxLines = 4,
  TextOverflow overflow = TextOverflow.ellipsis,
}) {
  if (_entry != null) {
    _removeInstantly();
  }

  _toastKey = GlobalKey<_ToastBubbleState>();

  _entry = OverlayEntry(
    builder: (ctx) {
      return Positioned(
        top: top ? margin.top : null,
        bottom: top ? null : margin.bottom,
        left: margin.left,
        right: margin.right,
        child: Material(
          type: MaterialType.transparency,
          child: _ToastBubble(
            key: _toastKey,
            message: message,
            backgroundColor: backgroundColor,
            textColor: textColor,
            textStyle: textStyle,
            icon: icon,
            iconSize: iconSize,
            duration: duration,
            padding: padding,
            radius: radius,
            elevation: elevation,
            shadowColor: shadowColor,
            borderColor: borderColor,
            borderWidth: borderWidth,
            top: top,
            maxLines: maxLines,
            overflow: overflow,
            onDismissed: () {
              _removeInstantly();
            },
          ),
        ),
      );
    },
  );

  Overlay.of(context).insert(_entry!);
}