showConfirmDialog function

Future showConfirmDialog(
  1. BuildContext context, {
  2. bool? isPositiveButtonVisible,
  3. String? title,
  4. String? body,
  5. String? positiveAction,
  6. String? negativeAction,
})

Implementation

Future<dynamic> showConfirmDialog(
  BuildContext context, {
  bool? isPositiveButtonVisible,
  String? title,
  String? body,
  String? positiveAction,
  String? negativeAction,
}) async {
  return showDialog<dynamic>(
    context: context,
    barrierDismissible: false, // user must tap button!
    builder: (BuildContext context) {
      return AlertDialog(
        title: Center(
          child: Text(
            title ?? 'Confirm Dialog',
            style:
                const TextStyle(color: CustomColors.defaultColor, fontSize: 20),
          ),
        ),
        content: SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
              Text(
                body ?? 'Do you want to delete this?',
                textAlign: TextAlign.center,
                style: const TextStyle(color: Colors.black, fontSize: 14),
              ),
            ],
          ),
        ),
        actions: <Widget>[
          Visibility(
            visible: isPositiveButtonVisible ?? true,
            child: ButtonWidget(
              height: 36,
              width: 100.0,
              marginBottom: 16.0,
              marginRight: 4.0,
              colorText: Colors.white,
              borderRadius: const BorderRadius.all(
                Radius.circular(5.0),
              ),
              colorButton: CustomColors.defaultColor,
              onPress: () {
                Navigator.of(context).pop(ConfirmTypes.approve);
              },
              textButton: positiveAction ?? 'Yes',
            ),
          ),
          ButtonWidget(
            height: 36,
            width: 100.0,
            marginBottom: 16.0,
            marginRight: 8.0,
            colorText: CustomColors.defaultColor,
            colorButton: Colors.white,
            borderRadius: const BorderRadius.all(
              Radius.circular(5.0),
            ),
            onPress: () {
              Navigator.of(context).pop(ConfirmTypes.cancel);
            },
            textButton: negativeAction ?? 'No',
          ),
        ],
      );
    },
  );
}