show static method

void show(
  1. BuildContext context, {
  2. required String message,
  3. ToastType type = ToastType.info,
  4. Duration duration = const Duration(seconds: 3),
  5. Color? backgroundColor,
  6. double borderRadius = 12,
  7. IconData? icon,
  8. bool fromBottom = false,
})

Implementation

static void show(
    BuildContext context, {
      required String message,
      ToastType type = ToastType.info,
      Duration duration = const Duration(seconds: 3),
      Color? backgroundColor,
      double borderRadius = 12,
      IconData? icon,
      bool fromBottom = false,
    }) {
  final overlay = Overlay.of(context);
  late OverlayEntry overlayEntry;

  overlayEntry = OverlayEntry(
    builder: (context) => Positioned(
      top: fromBottom ? null : MediaQuery.of(context).padding.top + 20,
      bottom: fromBottom ? 50 : null,
      left: 0,
      right: 0,
      child: _ToastWidget(
        message: message,
        type: type,
        onDismiss: () => overlayEntry.remove(),
        backgroundColor: backgroundColor,
        borderRadius: borderRadius,
        icon: icon,
      ),
    ),
  );

  overlay.insert(overlayEntry);
  Future.delayed(duration, () => overlayEntry.remove());
}