open static method

void open(
  1. BuildContext context, {
  2. double bottom = 24,
  3. Widget? btn,
  4. Widget? closeIcon,
  5. required Widget description,
  6. Duration? duration = const Duration(milliseconds: 4500),
  7. Widget? icon,
  8. required Widget message,
  9. Placement placement = Placement.topRight,
  10. double top = 24,
  11. void onClick()?,
  12. void onClose()?,
})

Implementation

static void open(
  BuildContext context, {
  double bottom = 24,
  Widget? btn,
  Widget? closeIcon,
  required Widget description,
  Duration? duration = const Duration(milliseconds: 4500),
  Widget? icon,
  required Widget message,
  Placement placement = Placement.topRight,
  double top = 24,
  void Function()? onClick,
  void Function()? onClose,
}) {
  var tops = GlobalQuery.of(context)?.notificationTops;
  var realTop = top;
  if (tops != null) {
    var heights = tops.values.toList();
    for (int i = 0; i < heights.length; i++) {
      realTop += heights[i] + 16;
    }
  }
  var key = GlobalKey();
  var entry = OverlayEntry(
    builder: (_) => _Notification(
      key: key,
      bottom: bottom,
      btn: btn,
      closeIcon: closeIcon,
      description: description,
      duration: duration,
      icon: icon,
      message: message,
      placement: placement,
      top: realTop,
      onClick: onClick,
      onClose: onClose,
    ),
  );
  Overlay.of(context)?.insert(entry);
  var height = key.currentContext?.size?.height ?? 120;
  GlobalQuery.of(context)?.insertNotification(key, height);
  if (duration != null) {
    Timer(duration, () {
      entry.remove();
      GlobalQuery.of(context)?.removeNotification(key);
    });
  }
}