normal_dialog.dart 4.3 KB
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../common/colors.dart';
import '../../utils/text_style_ms.dart';


class NormalDialog extends StatelessWidget {
  final String title;
  final String content;
  final String cancelBtnText;
  final String okBtnText;
  final VoidCallback? okOnClick;
  final VoidCallback? cancelOnClick;
  final bool showCancelBtn;
  final bool showOkBtn;

  const NormalDialog({
    Key? key,
    this.title = 'hint',
    this.content = '',
    this.okOnClick,
    this.cancelOnClick,
    this.showCancelBtn = true,
    this.showOkBtn = true,
    this.cancelBtnText = 'cancel',
    this.okBtnText = 'sure',
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Dialog(
      insetPadding: EdgeInsets.zero,
      backgroundColor: ColorConfig.red.withOpacity(0),
      child: Container(
        margin: const EdgeInsets.symmetric(horizontal: 34),
        padding: const EdgeInsets.only(top: 30),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(10),
          color: ColorConfig.white,
        ),
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Padding(
              padding: const EdgeInsets.symmetric(horizontal: 20),
              child: Text(
                title,
                style: const TextStyle(
                  color: ColorConfig.color33,
                  fontSize: 18,
                  fontWeight: FontWeight.w500,
                ),
              ),
            ),
            Container(
              padding: const EdgeInsets.only(
                  top: 27, bottom: 44, left: 10, right: 10),
              alignment: Alignment.center,
              width: double.infinity,
              child: Text(
                content,
                textAlign: TextAlign.center,
                style: TextStyleMs.color33_14_400.copyWith(height: 2.0),
              ),
            ),
            Container(
              height: 52,
              width: double.infinity,
              margin: const EdgeInsets.symmetric(horizontal: 12),
              decoration: const BoxDecoration(
                border: Border(
                  top: BorderSide(color: ColorConfig.colorF7F7F7, width: 1),
                ),
              ),
              child: Row(
                children: [
                  showCancelBtn
                      ? Expanded(
                    child: InkWell(
                      onTap: () {
                        Get.back(result: false);
                        if (cancelOnClick != null) {
                          cancelOnClick!();
                        }
                      },
                      child: Container(
                        child: Text(
                          cancelBtnText.tr,
                          style: TextStyleMs.color33_14_400,
                        ),
                        alignment: Alignment.center,
                        margin: const EdgeInsets.symmetric(vertical: 6),
                        decoration: showOkBtn
                            ? const BoxDecoration(
                          border: Border(
                            right: BorderSide(
                              color: ColorConfig.colorF7F7F7,
                              width: 1,
                            ),
                          ),
                        )
                            : const BoxDecoration(),
                      ),
                    ),
                  )
                      : Container(),
                  showOkBtn
                      ? Expanded(
                    child: InkWell(
                      onTap: () {
                        Get.back(result: true);
                        if (okOnClick != null) {
                          okOnClick!();
                        }
                      },
                      child: Container(
                        alignment: Alignment.center,
                        child: Text(
                          okBtnText.tr,
                          style: TextStyleMs.colorFF761E_14_400,
                        ),
                      ),
                    ),
                  )
                      : Container(),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}