phoenixPopUp function

void phoenixPopUp(
  1. {required BuildContext context,
  2. String? title,
  3. required String description,
  4. String? primaryButtonLabel,
  5. String? secondayButtonLabel,
  6. int type = 1,
  7. bool barrierDismissible = true,
  8. double space = 16,
  9. double elevation = 1.0,
  10. PhoenixPopupDirection direction = PhoenixPopupDirection.row,
  11. VoidCallback? ensureCallback,
  12. VoidCallback? cancelCallback}
)

Implementation

void phoenixPopUp({
  required BuildContext context,
  String? title,
  required String description,
  String? primaryButtonLabel,
  String? secondayButtonLabel,
  int type = 1,
  bool barrierDismissible = true,
  double space = 16,
  double elevation = 1.0,
  PhoenixPopupDirection direction = PhoenixPopupDirection.row,
  VoidCallback? ensureCallback,
  VoidCallback? cancelCallback,
}) {
  List<Widget> actions = [];

  if (secondayButtonLabel != null) {
    actions.add(
      Expanded(
        child: SizedBox(
          height: 45,
          width: double.infinity,
          child: ElevatedButton(
            onPressed: () {
              Navigator.of(context).pop();
              if (cancelCallback != null) {
                cancelCallback();
              }
            },
            style: ElevatedButton.styleFrom(
                backgroundColor: Colors.white,
                elevation: elevation,
                side: BorderSide(color: Theme.of(context).primaryColor)),
            child: Text(
              secondayButtonLabel,
              style: Theme.of(context).dialogTheme.contentTextStyle?.copyWith(
                        fontWeight: FontWeight.w500,
                        color: Theme.of(context).primaryColor,
                      ) ??
                  TextStyle(
                    fontWeight: FontWeight.w500,
                    color: Theme.of(context).primaryColor,
                  ),
            ),
          ),
        ),
      ),
    );
    if (primaryButtonLabel != null) {
      actions.add(
        SizedBox(
          width: space,
          height: space,
        ),
      );
    }
  }

  if (primaryButtonLabel != null) {
    actions.add(
      Expanded(
        child: SizedBox(
          height: 45,
          width: double.infinity,
          child: ElevatedButton(
            style: ElevatedButton.styleFrom(
              elevation: elevation,
              backgroundColor: Theme.of(context).primaryColor,
            ),
            onPressed: () {
              if (type == 1) {
                Navigator.of(context).pop();
              }
              if (ensureCallback != null) {
                ensureCallback();
              }
            },
            child: Text(
              primaryButtonLabel,
              style: Theme.of(context)
                  .dialogTheme
                  .contentTextStyle
                  ?.copyWith(color: Colors.white),
            ),
          ),
        ),
      ),
    );
  }

  showDialog(
    context: context,
    barrierDismissible: true,
    builder: (context) {
      return WillPopScope(
        onWillPop: () async => barrierDismissible,
        child: GestureDetector(
          onTap: () {
            if (barrierDismissible) Navigator.pop(context);
          },
          child: Scaffold(
            backgroundColor: Colors.transparent,
            body: Center(
              child: GestureDetector(
                onTap: () {},
                child: Container(
                  margin: const EdgeInsets.symmetric(horizontal: 20),
                  decoration: BoxDecoration(
                    color: Colors.white,
                    borderRadius: BorderRadius.circular(5),
                  ),
                  padding: const EdgeInsets.all(24),
                  child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      if (title != null) ...[
                        Text(
                          title,
                          style: const TextStyle(
                            color: Colors.black,
                            fontSize: 16,
                            fontWeight: FontWeight.w500,
                          ),
                        ),
                        const SizedBox(height: 10),
                      ],
                      Text(
                        description,
                        style: const TextStyle(
                          color: Color(0xFF75767A),
                          fontSize: 14,
                          fontWeight: FontWeight.w400,
                        ),
                      ),
                      const SizedBox(height: 20),
                      direction == PhoenixPopupDirection.column
                          ? SizedBox(
                              height: 100,
                              width: double.infinity,
                              child: Column(
                                children: actions.reversed.toList(),
                              ),
                            )
                          : Row(
                              mainAxisAlignment: MainAxisAlignment.spaceBetween,
                              children: actions,
                            )
                    ],
                  ),
                ),
              ),
            ),
          ),
        ),
      );
    },
  );
}