showErrorOverlay static method

void showErrorOverlay({
  1. Duration? duration,
  2. String? errorMessage,
  3. IconData? icon,
  4. double? overlayOpacity,
  5. void onDismiss()?,
})

Implementation

static void showErrorOverlay({
  Duration? duration,
  String? errorMessage,
  IconData? icon,
  double? overlayOpacity,
  void Function()? onDismiss,
}) {
  if (WidgetsBinding.instance.isRootWidgetAttached) {
    if (errorMessage == null) {
      _errorOverlayController.refresh();
      _errorOverlayController.state = _showCustomOverlay(
        (context, opacity) {
          return SButton(
            borderRadius: BorderRadius.circular(30),
            shouldBounce: false,
            child: Container(
              decoration: BoxDecoration(
                color: Colors.red.shade900
                    .withValues(alpha: overlayOpacity ?? 0.3),
                borderRadius: BorderRadius.circular(30),
              ),
            ).animate(
              effects: [
                FadeEffect(
                  duration: 0.12.sec,
                  curve: Curves.easeInOut,
                )
              ],
            ),
          );
        },
        duration: duration,
      );

      //execute onDismiss call
      Future.delayed(duration ?? 0.20.sec, () => dismissErrorOverlay());
      return;
    }

    //otherwise, show a PopThis,
    //the Timer delay is only to allow
    //any previous PopThis to first dismiss
    //then to show this one
    Timer(.2.sec, () {
      PopThis.animatedDismissPopThis();
      PopThis.pop(
        shouldSaveThisPop: false,
        onDismiss: onDismiss,
        duration: duration ?? 4.sec,
        popBackgroundColor: Colors.white.withValues(alpha: 0.9),
        dismissBarrierColor:
            Colors.red.shade900.withValues(alpha: overlayOpacity ?? 0.7),
        child: SingleChildScrollView(
          child: Column(
            children: [
              Icon(
                icon ?? Iconsax.shield_cross_bold,
                color: Colors.red,
                size: 40,
              ),
              Padding(
                padding: const EdgeInsets.only(top: 20.0),
                child: Text(
                  errorMessage,
                  textAlign: TextAlign.center,
                  style: const TextStyle(
                    fontWeight: FontWeight.w600,
                  ),
                ),
              ),
            ],
          ),
        ),
      );
    });
  }

  //if GetMaterial is not initialised yet
  onDismiss?.call();
}