showAlertCustom static method

void showAlertCustom(
  1. BuildContext context, {
  2. String? title,
  3. WidgetBuilder? builder,
  4. String? content,
  5. Function? onConfirm,
  6. String? textCancel = '取消',
  7. String? textConfirm = '确定',
  8. bool isCancelable = true,
  9. Function? onCancel,
})

Implementation

static void showAlertCustom(BuildContext context,
    {String? title,
    WidgetBuilder? builder,
    String? content,
    Function? onConfirm,
    String? textCancel = '取消',
    String? textConfirm = '确定',
    bool isCancelable = true,
    Function? onCancel}) {
  showDialog(
    context: context,
    barrierDismissible: isCancelable,
    builder: (BuildContext context) => AlertDialog(
      title: Text(
        title.mxText,
        overflow: TextOverflow.ellipsis,
        style: TextStyle(
            fontSize: 16.fsp,
            color: Colors.black,
            fontWeight: FontWeight.w500,
            fontStyle: FontStyle.normal),
      ),
      backgroundColor: Colors.white,
      contentPadding: EdgeInsets.all(0.0),
      titleTextStyle: TextStyle(fontStyle: FontStyle.normal),
      content: Container(
        color: UIData.pureWhite,
        child: Padding(
          padding: EdgeInsets.symmetric(horizontal: 25.vsp),
          child: VStack(
            [
              20.vSpacer(),
              builder != null ? builder(context) : MyBlackText('$content'),
              5.vSpacer(),
              20.vSpacer(),
              HStack(
                [
                  Spacer(),
                  MyFlatRoundedConcreteBtn(
                    textCancel,
                    UIData.clickColor(),
                    () {
                      Navigator.pop(context, 'Cancel');
                    },
                    titleColor: '#AAAAAA'.hexColor(),
                    paddingH: 15.hsp,
                    height: 30.vsp,
                    radius: 15.vsp,
                  ),
                  5.widthBox,
                  MyFlatRoundedConcreteBtn(
                    textConfirm!.textEmpty() ? '确定' : textConfirm,
                    UIData.clickColor(),
                    () {
                      Navigator.pop(context, 'OK');
                    },
                    titleColor: UIData.primaryColor,
                    paddingH: 20,
                    height: 30.vsp,
                    radius: 15.vsp,
                  )
                ],
                alignment: MainAxisAlignment.end,
              ).h(30.vsp),
              15.vSpacer(),
            ],
            crossAlignment: CrossAxisAlignment.center,
          ),
        ),
      ).cornerRadius(UIData.defRadius),
      actions: <Widget>[],
    ),
  ).then<String>((returnVal) async {
    if (returnVal != null) {
      if (returnVal == 'OK') {
        if (onConfirm != null) onConfirm();
      } else {
        if (onCancel != null) onCancel();
      }
    }
    return '';
  });
}