showTopSnackBar function

void showTopSnackBar({
  1. required BuildContext context,
  2. required SeniorNotificationSnackbar child,
  3. OverlayState? overlayState,
})

Implementation

void showTopSnackBar({
  required BuildContext context,
  required SeniorNotificationSnackbar child,
  OverlayState? overlayState,
}) async {
  overlayState ??= Overlay.of(context);
  late OverlayEntry overlayEntry;
  overlayEntry = OverlayEntry(
    builder: (_) {
      return _SeniorTopSnackbar(
        child: child,
        onDismissed: () {
          overlayEntry.remove();
          _previousEntry = null;
        },
        onTap: () {
          child.seniorNotificationSnackBarAction?.onPressed?.call();
        },
      );
    },
  );

  _previousEntry?.remove();
  overlayState.insert(overlayEntry);
  _previousEntry = overlayEntry;
}