dilemma<T> static method

Future<T?> dilemma<T>(
  1. BuildContext context, {
  2. required String title,
  3. required String content,
  4. String rightButton = "OK",
  5. String leftButton = "CANCEL",
  6. bool centerContent = false,
  7. bool? dark,
  8. VoidCallback? onTapedRight,
  9. VoidCallback? onTapedLeft,
})

选择项,确定或者取消。

用途

  • 参数选择
  • 内容判断
  • 条款确认

参数 |参数名|描述|是否必须|

  • context 上下文
  • title 信息标题
  • centerContent 是否居中显示,默认不居中。
  • onTapedRight 按钮点击事件响应。
  • onTapedLeft 排版,左边缩进的距离。
  • dark 是否强制指定夜间模式或者白天模式,不设置使用系统默认。

Implementation

static Future<T?> dilemma<T>(
  BuildContext context, {
  required String title,
  required String content,
  String rightButton = "OK",
  String leftButton = "CANCEL",
  bool centerContent = false,
  bool? dark,
  VoidCallback? onTapedRight,
  VoidCallback? onTapedLeft,
}) {
  bool _dark = dark ?? (Theme.of(context).brightness == Brightness.dark);
  Color _fontColor = _dark ? Colors.white : Colors.black;
  return showDialog<T>(
    context: context,
    builder: (context) {
      return Dialog(
        backgroundColor: _dark ? Colors.black87 : Colors.white,
        // 对话框区域背景色
        elevation: 12.0,
        insetPadding: EdgeInsets.zero,
        clipBehavior: Clip.antiAlias,
        shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(18.0),
        ),
        // insetAnimationCurve: Curves.easeInOutQuad,
        // insetAnimationDuration: Duration(milliseconds: 5000),
        child: TernaryContainer(
            inDialog: true,
            header: Container(
                alignment: Alignment.center,
                padding: EdgeInsets.only(top: 25.0, bottom: 10.0),
                child: Text(
                  title,
                  style: TextStyle(
                      color: _fontColor,
                      fontSize: 18.0,
                      shadows: kElevationToShadow[4]),
                )),
            content: Container(
              padding: EdgeInsets.only(
                  top: 10.0, bottom: 20.0, left: 20.0, right: 10.0),
              child: Text(
                content,
                textAlign: centerContent ? TextAlign.center : TextAlign.left,
                style: TextStyle(
                  color: _fontColor,
                ),
              ),
            ),
            footer: Column(
              children: [
                Divider(
                  color: Colors.grey,
                  height: 2,
                ),
                Container(
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          child: TextButton(
                            onPressed: onTapedLeft,
                            child: Text(
                              leftButton,
                              textAlign: TextAlign.center,
                              style: TextStyle(fontSize: 16.0),
                            ),
                          ),
                        ),
                      ),
                      Container(
                          height: 48,
                          child: const VerticalDivider(
                            color: Colors.grey,
                            width: 2,
                          )),
                      Expanded(
                        child: Container(
                          alignment: Alignment.center,
                          child: TextButton(
                            onPressed: onTapedRight,
                            child: Text(
                              rightButton,
                              textAlign: TextAlign.center,
                              style: TextStyle(fontSize: 16.0),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
                // SizedBox(height: 10.0,),
              ],
            )),
      );
    },
  );
}