dart - 如何在Flutter中将对话框底部的两个按钮对齐

标签 dart flutter

这是我要在Flutter中创建的对话框的模型:

Screenshot

这是我到目前为止的内容:

Screenshot

我无法将两个带有圆角底角的按钮放置在对话框的底部,以使其看起来像模型中的样子。

我能够使这些按钮适合Dialog宽度,而无需堆栈,但是它将位于顶部。

这是对话框的代码:

SimpleDialog carDialog = SimpleDialog(
      contentPadding: EdgeInsets.all(0),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
      children: <Widget>[
        Container(
          height: 400,
          child: Stack(
            children: <Widget>[
              Positioned(
                bottom: 0,
                child: IntrinsicWidth(
                  child: Row(
                    mainAxisSize: MainAxisSize.min,
                    children: <Widget>[
                      Expanded(
                        child: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                bottomLeft: Radius.circular(6)),
                            color: Colors.lightBlueAccent,
                          ),
                          height: 45,
                          child: Center(
                            child: Text(
                              allTranslations.text('wait_enroute').toUpperCase(),
                              textAlign: TextAlign.center,
                              style: Fonts.appFont(context,
                                  bold: true, color: Colors.white),
                            ),
                          ),
                        ),
                      ),
                      Expanded(
                        child: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.only(
                                bottomRight: Radius.circular(6)),
                            color: AppColors.action_button,
                          ),
                          height: 45,
                          child: Center(
                            child: Padding(
                              padding:
                                  const EdgeInsets.symmetric(horizontal: 8.0),
                              child: Text(
                                allTranslations.text('new_order').toUpperCase(),
                                textAlign: TextAlign.center,
                                style: Fonts.appFont(context,
                                    bold: true, color: Colors.white),
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ],
    );

    showDialog(context: context, builder: (context) => carDialog);

最佳答案

我找到了可行的解决方案。它不需要Stack小部件,所有内容都可以嵌套在Column中,如下所示:

SimpleDialog carDialog = SimpleDialog(
      contentPadding: EdgeInsets.all(0),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(6)),
      children: <Widget>[
        Column(
          children: <Widget>[
            SizedBox(
              height: 400,
            ),
            Row(
              mainAxisSize: MainAxisSize.min,
              children: <Widget>[
                Expanded(
                  child: InkWell(
                    child: Container(
                      decoration: BoxDecoration(
                        borderRadius:
                            BorderRadius.only(bottomLeft: Radius.circular(6)),
                        color: Colors.lightBlueAccent,
                      ),
                      height: 45,
                      child: Center(
                        child: Text(
                          allTranslations.text('wait_enroute').toUpperCase(),
                          textAlign: TextAlign.center,
                          style: Fonts.appFont(context,
                              bold: true, color: Colors.white),
                        ),
                      ),
                    ),
                  ),
                ),
                Expanded(
                  child: Container(
                    decoration: BoxDecoration(
                      borderRadius:
                          BorderRadius.only(bottomRight: Radius.circular(6)),
                      color: AppColors.action_button,
                    ),
                    height: 45,
                    child: Center(
                      child: Padding(
                        padding: const EdgeInsets.symmetric(horizontal: 8.0),
                        child: Text(
                          allTranslations.text('new_order').toUpperCase(),
                          textAlign: TextAlign.center,
                          style: Fonts.appFont(context,
                              bold: true, color: Colors.white),
                        ),
                      ),
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ],
    );

    showDialog(context: context, builder: (context) => carDialog);

结果:

Screenshot

关于dart - 如何在Flutter中将对话框底部的两个按钮对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56055033/

相关文章:

dart - 检测在模拟器或真实设备上运行的应用

dart - Flutter TextFormField 聚焦时重新加载当前屏幕

flutter - 从 DateTime 类中获取意外日期

Flutter : Android Gradle plugin requires Java 11 to run. 您当前使用的是 Java 1.8

flutter 酒吧发布 : Could not find an option named "dry-run"

dart - Flutter - 广播动画未显示在 showDialog 上

flutter - 如何在Flutter中重命名或删除Excel工作表?

flutter - 展开新的ExpansionTile时折叠ExpansionTile

flutter - 如何在 Flutter 中 move 屏幕中的小部件

dart - fileSystem.chooseEntry from package :chrome/app. dart 生成运行时错误