phoenixGenericPopUp function

void phoenixGenericPopUp({
  1. required BuildContext context,
  2. required Widget popUpContentWidget,
  3. Widget? popUpTitleWidget,
  4. Widget? ensureWidget,
  5. Widget? cancelWidget,
  6. int type = 1,
  7. bool barrierDismissible = false,
  8. VoidCallback? ensureCallback,
  9. VoidCallback? cancelCallback,
})

Implementation

void phoenixGenericPopUp({
  required BuildContext context,
  //message related
  required Widget popUpContentWidget,
  //title related
  Widget? popUpTitleWidget,
  //ensure button related
  Widget? ensureWidget,
  //cancel button related
  Widget? cancelWidget,
  // type != 1 will not dismiss button on ensure click
  int type = 1,
  bool barrierDismissible = false,
  VoidCallback? ensureCallback,
  VoidCallback? cancelCallback,
}) {
  List<Widget> actions = [];

  if (cancelWidget != null) {
    if (cancelWidget.runtimeType == Text) {
      if ((cancelWidget as Text).data!.isNotEmpty) {
        if (Platform.isIOS) {
          actions.add(
            cupertinoButtonFunction(
              context,
              cancelWidget,
              cancelCallback,
              type,
              0, //0 for cancelwidget
            ),
          );
        } else {
          actions.add(
            elevatedButtonFunction(
              context,
              cancelWidget,
              cancelCallback,
              type,
              0, //0 for cancelwidget
            ),
          );
        }
      }
    } else {
      if (Platform.isIOS) {
        actions.add(
          cupertinoButtonFunction(
            context,
            cancelWidget,
            cancelCallback,
            type,
            0, //0 for cancelwidget
          ),
        );
      } else {
        actions.add(
          elevatedButtonFunction(
            context,
            cancelWidget,
            cancelCallback,
            type,
            0, //0 for cancelwidget
          ),
        );
      }
    }
  }
  if (Platform.isIOS) {
    actions.add(
      cupertinoButtonFunction(
        context,
        ensureWidget ??
            const Text(
              "Confirm",
            ),
        ensureCallback,
        type,
        1, //1 for ensureWidget
      ),
    );
  } else {
    actions.add(
      elevatedButtonFunction(
        context,
        ensureWidget ??
            const Text(
              "Confirm",
            ),
        ensureCallback,
        type,
        1, //1 for ensureWidget
      ),
    );
  }
  if (Platform.isIOS) {
    showDialog(
      barrierDismissible: barrierDismissible,
      context: context,
      builder: (context) {
        return WillPopScope(
          onWillPop: () async => barrierDismissible,
          child: CupertinoAlertDialog(
            title: (() {
              if (popUpTitleWidget.runtimeType == Text) {
                if ((popUpTitleWidget as Text).data!.isNotEmpty) {
                  return popUpTitleWidget;
                } else {
                  return null;
                }
              } else {
                return popUpTitleWidget;
              }
            }()),
            content: popUpContentWidget,
            actions: actions,
          ),
        );
      },
    );
  } else {
    showDialog(
      context: context,
      barrierDismissible: barrierDismissible,
      builder: (context) {
        return WillPopScope(
          onWillPop: () async => barrierDismissible,
          child: AlertDialog(
            title: (() {
              if (popUpTitleWidget.runtimeType == Text) {
                if ((popUpTitleWidget as Text).data!.isNotEmpty) {
                  return popUpTitleWidget;
                } else {
                  return null;
                }
              } else {
                return popUpTitleWidget;
              }
            }()),
            content: popUpContentWidget,
            actions: actions,
          ),
        );
      },
    );
  }
}