showNsgDialog function

Future showNsgDialog({
  1. required BuildContext context,
  2. bool showCancelButton = true,
  3. bool showCloseButton = false,
  4. String? title,
  5. String? text,
  6. String? textConfirm,
  7. String? textCancel,
  8. Widget? child,
  9. Color? titleBackColor,
  10. Color? titleTextColor,
  11. List<Widget>? buttons,
  12. VoidCallback? onConfirm,
  13. VoidCallback? onCancel,
})

Implementation

Future<dynamic> showNsgDialog({
  required BuildContext context,
  bool showCancelButton = true,
  bool showCloseButton = false,
  String? title,
  String? text,
  String? textConfirm,
  String? textCancel,
  Widget? child,
  Color? titleBackColor,
  Color? titleTextColor,
  List<Widget>? buttons,
  VoidCallback? onConfirm,
  VoidCallback? onCancel,
}) {
  return showDialog(
    context: context,
    builder: (context) {
      title ??= tran.need_confirmation;
      text ??= tran.are_you_sure;
      textConfirm ??= tran.ok.toUpperCase();
      textCancel ??= tran.cancel;
      return nsgBackDrop(
        child: Material(
          color: Colors.transparent,
          child: Container(
            padding: const EdgeInsets.all(20),
            decoration: BoxDecoration(color: nsgtheme.colorModalBack, borderRadius: BorderRadius.circular(10)),
            child: Center(
              child: Container(
                constraints: const BoxConstraints(maxWidth: 640),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                      alignment: Alignment.center,
                      width: double.infinity,
                      decoration: BoxDecoration(color: titleBackColor ?? nsgtheme.colorMain),
                      padding: const EdgeInsets.symmetric(horizontal: 5),
                      constraints: BoxConstraints(minHeight: 50),
                      child: Row(
                        children: [
                          if (showCloseButton) SizedBox(width: 50),
                          Expanded(
                            child: Text(
                              title!,
                              textAlign: TextAlign.center,
                              style: TextStyle(color: titleTextColor ?? nsgtheme.colorPrimaryText, fontSize: nsgtheme.sizeXL, fontWeight: FontWeight.bold),
                            ),
                          ),
                          if (showCloseButton)
                            Container(
                              margin: EdgeInsets.symmetric(vertical: 5, horizontal: 3),
                              decoration: BoxDecoration(color: titleTextColor ?? nsgtheme.colorPrimaryText, borderRadius: BorderRadius.circular(10)),
                              child: IconButton(
                                icon: Icon(Icons.close, color: titleBackColor ?? nsgtheme.colorPrimary, size: 24), // set your color here
                                onPressed: () async {
                                  Navigator.of(context).pop();
                                },
                              ),
                            ),
                        ],
                      ),
                    ),
                    Container(
                      width: double.infinity,
                      decoration: BoxDecoration(color: nsgtheme.colorMainBack),
                      child: Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 30, vertical: 30),
                        child: child ?? Text(text!, textAlign: TextAlign.center),
                      ),
                    ),
                    if (buttons != null && buttons.isEmpty)
                      SizedBox()
                    else
                      Container(
                        alignment: Alignment.center,
                        decoration: BoxDecoration(color: nsgtheme.colorMainBack.withAlpha(230)),
                        padding: const EdgeInsets.all(15),
                        child: NsgGrid(
                          vGap: 10,
                          hGap: 10,
                          width: 300,
                          children:
                              buttons ??
                              [
                                if (showCancelButton)
                                  NsgButton(
                                    onPressed: () {
                                      if (onCancel != null) {
                                        onCancel();
                                        Navigator.of(context).pop();
                                      } else {
                                        Navigator.of(context).pop();
                                      }
                                    },
                                    width: 150,
                                    height: 40,
                                    text: textCancel,
                                    color: Colors.black,
                                    backColor: nsgtheme.colorGrey,
                                  ),
                                NsgButton(
                                  onPressed: () {
                                    Navigator.of(context).pop();
                                    if (onConfirm != null) onConfirm();
                                  },
                                  width: 150,
                                  height: 40,
                                  text: textConfirm,
                                ),
                              ],
                        ),
                      ),
                  ],
                ),
              ),
            ),
          ),
        ),
      );
    },
  );
}