openDialog static method

void openDialog({
  1. required BuildContext context,
  2. Widget content = const SizedBox(),
  3. String title = '',
  4. List<CuReDialogAction> actions = const [],
})

Implementation

static void openDialog(
    {required BuildContext context,
    Widget content = const SizedBox(),
    String title = '',
    List<CuReDialogAction> actions = const []}) {
  if (isIos()) {
    showCupertinoDialog(
        context: context,
        builder: (context) {
          return CupertinoAlertDialog(
            title: title != '' ? Text(title) : null,
            content: content,
            actions: actions.isNotEmpty
                ? [
                    for (var action in actions)
                      CupertinoDialogAction(
                        child: Text(
                          action.label,
                          style: TextStyle(
                            fontSize: 14,
                            color: action.color ?? CuReDesign.primaryColor,
                          ),
                        ),
                        onPressed: () {
                          Navigator.pop(context);
                          if (action.onPressed != null) action.onPressed!();
                        },
                      ),
                  ]
                : [
                    CupertinoDialogAction(
                      child: Text(
                        'Ok',
                        style: TextStyle(
                          fontSize: 14,
                          color: CuReDesign.primaryColor,
                        ),
                      ),
                      onPressed: () {
                        Navigator.pop(context);
                      },
                    ),
                  ],
          );
        });
  } else {
    showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: title != '' ? Text(title) : null,
          content: content,
          actions: actions.isNotEmpty
              ? [
                  for (var action in actions)
                    TextButton(
                      onPressed: () {
                        Navigator.pop(context);
                        if (action.onPressed != null) action.onPressed!();
                      },
                      child: Text(
                        action.label,
                        style: TextStyle(
                          color: action.color ?? CuReDesign.primaryColor,
                        ),
                      ),
                    ),
                ]
              : [
                  TextButton(
                    onPressed: () {
                      Navigator.pop(context);
                    },
                    child: Text(
                      'Ok',
                      style: TextStyle(
                        color: CuReDesign.primaryColor,
                      ),
                    ),
                  ),
                ],
        );
      },
    );
  }
}