createHighlightOverlay static method

Future<void> createHighlightOverlay({
  1. String? text,
  2. required BuildContext context,
  3. Color? bgColor,
  4. Color? borderColor,
  5. Color? textColor,
  6. bool hasCloseIcon = true,
  7. Widget? closeIcon,
  8. Duration? duration,
  9. double? radius,
  10. double? width,
  11. double? height,
  12. EdgeInsets? padding,
  13. EdgeInsets? margin,
  14. Alignment? alignment,
  15. dynamic onClosedTap()?,
  16. bool autoClose = true,
  17. Widget? body,
})

Implementation

static Future<void> createHighlightOverlay({
  String? text,
  required BuildContext context,
  Color? bgColor,
  Color? borderColor,
  Color? textColor,
  bool hasCloseIcon = true,
  Widget? closeIcon,
  Duration? duration,
  double? radius,
  double? width,
  double? height,
  EdgeInsets? padding,
  EdgeInsets? margin,
  Alignment? alignment,
  Function()? onClosedTap,
  bool autoClose = true,
  Widget? body,
}) async {
  // Remove the existing OverlayEntry.
  removeHighlightOverlay();

  assert(overlayEntry == null);

  duration ??= 5.seconds;

  overlayEntry = OverlayEntry(
    // Create a new OverlayEntry.
    builder: (BuildContext context) {
      // Align is used to position the highlight overlay
      // relative to the NavigationBar destination.
      return Material(
        color: Clr.colorTransparent,
        elevation: 0,
        child: SafeArea(
          child: Align(
            alignment: alignment ?? Alignment.topRight,
            heightFactor: 1.0,
            child: body ??
                Container(
                  decoration: pBoxDecoration(
                    color: bgColor ?? Colors.blueAccent,
                    radius: radius ?? 6,
                    borderColor: borderColor,
                    hasBorder: borderColor != null,
                  ),
                  padding: padding ??
                      const EdgeInsets.symmetric(horizontal: 16, vertical: 10),
                  margin: margin ?? const EdgeInsets.all(30),
                  constraints: BoxConstraints(
                      minWidth: Get.width * 0.4,
                      maxHeight: Get.width * 0.8,
                      minHeight: 0.0,
                      maxWidth: Get.height * 0.8),
                  height: height == null ? null : (height + 1),
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Flexible(
                          child: Txt(
                        text,
                        textColor: textColor,
                      )),
                      if (hasCloseIcon)
                        IconButton(
                          onPressed: onClosedTap ??
                              () {
                                removeHighlightOverlay();
                              },
                          icon: const Icon(Icons.close),
                          visualDensity: VisualDensity.compact,
                        )
                    ],
                  ),
                ),
          ),
        ),
      );
    },
  );

  // Add the OverlayEntry to the Overlay.
  Overlay.of(context).insert(overlayEntry!);
  if (autoClose) {
    await Future.delayed(duration);
    removeHighlightOverlay();
  }
}