showDialog static method

void showDialog({
  1. required Widget content,
  2. Widget? title,
  3. List<Widget>? actions,
  4. Widget? cancel,
  5. Widget? confirm,
  6. VoidCallback? onConfirm,
  7. VoidCallback? onCancel,
  8. MainAxisAlignment? actionsAlignment,
  9. bool close = false,
  10. Widget? foot,
  11. bool barrierDismissible = true,
})

Implementation

static void showDialog({
  required Widget content,
  Widget? title,
  List<Widget>? actions,
  Widget? cancel,
  Widget? confirm,
  VoidCallback? onConfirm,
  VoidCallback? onCancel,
  MainAxisAlignment? actionsAlignment,
  bool close = false,
  Widget? foot,
  bool barrierDismissible = true,
}) {
  Get.dialog(
    barrierDismissible: close ? false : barrierDismissible,
    Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        AlertDialog.adaptive(
          title: title,
          titleTextStyle: Theme.of(Get.context!).textTheme.titleMedium,
          shape: RoundedRectangleBorder(
            borderRadius:
                BorderRadius.all(Radius.circular(CommonStyle.roundedMd)),
          ),
          content: Column(
            children: [
              content,
              const SizedBox(height: 20),
              ...actions ??
                  <Widget>[
                    Row(
                      children: [
                        Expanded(
                          child: ComButton(
                            plain: true,
                            child: cancel ?? Text('取消'.tr),
                            onPressed: () => onCancel != null
                                ? onCancel.call()
                                : Get.back(),
                          ),
                        ),
                        SizedBox(width: CommonStyle.spaceMd),
                        Expanded(
                          child: ComButton(
                            gradient: CommonColors.primaryGradient,
                            child: confirm ?? Text('确定'.tr),
                            onPressed: () => onConfirm?.call(),
                          ),
                        ),
                      ],
                    ),
                  ]
            ],
          ),
        ),
        Visibility(
          visible: close,
          child: foot ??
              Container(
                padding: const EdgeInsets.all(6),
                decoration: BoxDecoration(
                  border: Border.all(
                    color: Colors.white60, // 边框颜色
                    width: 1.0, // 边框宽度
                  ),
                  borderRadius: BorderRadius.circular(CommonStyle.rounded),
                ),
                child: GestureDetector(
                  child: const Icon(
                    Icons.close,
                    size: 20,
                    color: Colors.white60,
                  ),
                  onTap: () {
                    Get.back();
                  },
                ),
              ),
        )
      ],
    ),
  );
}