show static method

void show(
  1. BuildContext context, {
  2. required String message,
  3. NiceNotificationType type = NiceNotificationType.info,
  4. Duration duration = const Duration(seconds: 3),
  5. String? actionLabel,
  6. VoidCallback? onAction,
})

Show a toast notification

Implementation

static void show(
  BuildContext context, {
  required String message,
  NiceNotificationType type = NiceNotificationType.info,
  Duration duration = const Duration(seconds: 3),
  String? actionLabel,
  VoidCallback? onAction,
}) {
  final overlay = Overlay.of(context);
  late OverlayEntry entry;

  entry = OverlayEntry(
    builder: (context) => Positioned(
      bottom: 50,
      left: 0,
      right: 0,
      child: Center(
        child: Material(
          color: Colors.transparent,
          child: NiceToast(
            message: message,
            type: type,
            duration: duration,
            actionLabel: actionLabel,
            onAction: onAction,
            onDismiss: () => entry.remove(),
          ),
        ),
      ),
    ),
  );

  overlay.insert(entry);

  Future.delayed(duration, () {
    if (entry.mounted) {
      entry.remove();
    }
  });
}