showWcModal function

void showWcModal(
  1. BuildContext context,
  2. WcBaseError error, {
  3. Color backgroundColor = Colors.deepPurple,
  4. Color textColor = Colors.white,
  5. IconData icon = Icons.error_outline,
  6. Color iconColor = Colors.white,
  7. int durationSeconds = 3,
  8. double height = 300,
  9. double width = 200,
  10. Alignment alignment = Alignment.center,
  11. VoidCallback? onPressed,
})

Implementation

void showWcModal(
  BuildContext context,
  WcBaseError error, {
  Color backgroundColor = Colors.deepPurple,
  Color textColor = Colors.white,
  IconData icon = Icons.error_outline,
  Color iconColor = Colors.white,
  int durationSeconds = 3,
  double height = 300,
  double width = 200,
  Alignment alignment = Alignment.center,
  VoidCallback? onPressed,
}) {
  final overlay = Overlay.of(context);
  late OverlayEntry overlayEntry;

  overlayEntry = OverlayEntry(
    builder: (context) => Align(
      alignment: alignment,
      child: Padding(
        padding: const EdgeInsets.all(8.0),
        child: SizedBox(
          width: width,
          height: height,
          child: WcModal(
            error: error,
            backgroundColor: backgroundColor,
            textColor: textColor,
            icon: icon,
            iconColor: iconColor,
            onPressed: () {
              if (onPressed != null) {
                onPressed();
              }
              if (overlayEntry.mounted) {
                overlayEntry.remove();
              }
            },
          ),
        ),
      ),
    ),
  );

  overlay.insert(overlayEntry);

  Future.delayed(Duration(seconds: durationSeconds), () {
    if (overlayEntry.mounted) {
      overlayEntry.remove();
    }
  });
}