cShowAlwaysOnTopAlert function

void cShowAlwaysOnTopAlert({
  1. required BuildContext context,
  2. required String message,
  3. String? title,
  4. String? okText,
  5. dynamic ok()?,
  6. String? cancelText,
  7. dynamic cancel()?,
  8. double width = 400,
})

Shows a full-screen alert on top of all other widgets in the app.

This alert is not modal and does not block user interaction with the rest of the app. Instead, it simply overlays the alert at the top of the screen.

The alert can be dismissed by calling cCloseAlwaysOnTopAlert.

If an alert is already being shown when this function is called, it will be automatically dismissed before the new alert is shown.

The provided context is used to access the Overlay object that the alert is inserted into. The alert is not necessarily shown relative to the positions of the widgets in the given context.

The message argument is the text that will be displayed in the alert.

The title, okText, and cancelText arguments are all optional and default to null. If not null, they will be used as the title of the alert and the text of the OK and cancel buttons, respectively.

The ok and cancel arguments are callbacks that will be invoked when the user taps the OK and cancel buttons, respectively. If null, the alert will not have OK and cancel buttons.

The width argument is the width of the alert in logical pixels. Defaults to 400.

Implementation

void cShowAlwaysOnTopAlert({
  required BuildContext context,
  required String message,
  String? title,
  String? okText,
  Function()? ok,
  String? cancelText,
  Function()? cancel,
  double width = 400,
}) {
  if (cAlertOverlayEntry != null) {
    // If an alert is already being shown, remove it first
    cAlertOverlayEntry!.remove();
  }

  cAlertOverlayEntry = OverlayEntry(
    builder: (context) => TopAlert(
      message: message,
      title: title,
      ok: ok,
      okText: okText,
      cancelText: cancelText,
      cancel: cancel,
      width: width,
    ),
  );

  // Insert the overlay entry into the overlay
  Overlay.of(context).insert(cAlertOverlayEntry!);
}