我正在try 创建一个带有圆角的alert 对话框,如下面的截图所示.另外,在这里添加我的代码,但我的输出与预期的完全不同.有没有人,请帮帮我.

预期的alert 对话框

预期alert 对话框

我的密码在这里.

void _showAlert() {
AlertDialog dialog = new AlertDialog(
  content: new Container(
    width: 260.0,
    height: 230.0,
    decoration: new BoxDecoration(
      shape: BoxShape.rectangle,
      color: const Color(0xFFFFFF),
      borderRadius: new BorderRadius.all(new Radius.circular(32.0)),
    ),
    child: new Column(
      crossAxisAlignment: CrossAxisAlignment.stretch,
      children: <Widget>[
        // dialog top
        new Expanded(
          child: new Row(
            children: <Widget>[
              new Container(
                // padding: new EdgeInsets.all(10.0),
                decoration: new BoxDecoration(
                  color: Colors.white,
                ),
                child: new Text(
                  'Rate',
                  style: TextStyle(
                    color: Colors.black,
                    fontSize: 18.0,
                    fontFamily: 'helvetica_neue_light',
                  ),
                  textAlign: TextAlign.center,
                ),
              ),
            ],
          ),
        ),

        // dialog centre
        new Expanded(
          child: new Container(
              child: new TextField(
            decoration: new InputDecoration(
              border: InputBorder.none,
              filled: false,
              contentPadding: new EdgeInsets.only(
                  left: 10.0, top: 10.0, bottom: 10.0, right: 10.0),
              hintText: ' add review',
              hintStyle: new TextStyle(
                color: Colors.grey.shade500,
                fontSize: 12.0,
                fontFamily: 'helvetica_neue_light',
              ),
            ),
          )),
          flex: 2,
        ),

        // dialog bottom
        new Expanded(
          child: new Container(
            padding: new EdgeInsets.all(16.0),
            decoration: new BoxDecoration(
              color: const Color(0xFF33b17c),
            ),
            child: new Text(
              'Rate product',
              style: TextStyle(
                color: Colors.white,
                fontSize: 18.0,
                fontFamily: 'helvetica_neue_light',
              ),
              textAlign: TextAlign.center,
            ),
          ),
        ),
      ],
    ),
  ),
);

showDialog(context: context, child: dialog);
}
}

我从上面的代码中得到的输出是.

屏幕截图

推荐答案

设置BoxDecory的容器位于警告对话框下的小部件树中.这意味着您只在对话框的填充中设置了一个框.您需要创建一个自定义AlertDialog/showDialog并在那里设置半径.在自定义小部件中,您还可以添加按钮以及除了填充之外需要工作的所有内容.

当您在项目(gist.github.com)中包含customShowDialog.dart文件时,您可以在此处编辑半径borderRadius: BorderRadius.all(Radius.circular(20.0)),并按如下方式调用它:

return new CustomAlertDialog(
    content: new Container(
        width: 260.0,
        height: 230.0,
        decoration: new BoxDecoration(
        shape: BoxShape.rectangle,
        color: const Color(0xFFFFFF),
        borderRadius:
            new BorderRadius.all(new Radius.circular(32.0)),
        ),
        child: new Column(
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: <Widget>[
            // dialog top
            new Expanded(
            child: new Row(
                children: <Widget>[
                new Container(
                    // padding: new EdgeInsets.all(10.0),
                    decoration: new BoxDecoration(
                    color: Colors.white,
                    ),
                    child: new Text(
                    'Rate',
                    style: TextStyle(
                        color: Colors.black,
                        fontSize: 18.0,
                        fontFamily: 'helvetica_neue_light',
                    ),
                    textAlign: TextAlign.center,
                    ),
                ),
                ],
            ),
            ),

            // dialog centre
            new Expanded(
            child: new Container(
                child: new TextField(
                decoration: new InputDecoration(
                border: InputBorder.none,
                filled: false,
                contentPadding: new EdgeInsets.only(
                    left: 10.0,
                    top: 10.0,
                    bottom: 10.0,
                    right: 10.0),
                hintText: ' add review',
                hintStyle: new TextStyle(
                    color: Colors.grey.shade500,
                    fontSize: 12.0,
                    fontFamily: 'helvetica_neue_light',
                ),
                ),
            )),
            flex: 2,
            ),

            // dialog bottom
            new Expanded(
            child: new Container(
                padding: new EdgeInsets.all(16.0),
                decoration: new BoxDecoration(
                color: const Color(0xFF33b17c),
                ),
                child: new Text(
                'Rate product',
                style: TextStyle(
                    color: Colors.white,
                    fontSize: 18.0,
                    fontFamily: 'helvetica_neue_light',
                ),
                textAlign: TextAlign.center,
                ),
            ),
            ),
        ],
        ),
    ),
    );
});

你会得到这样的结果:

enter image description here

EDIT:

虽然Ffltter最近推出了shape property,这将通过设置ShapeBorder来帮助您处理圆角,例如

shape: RoundedRectangleBorder(
    borderRadius: BorderRadius.all(Radius.circular(20.0))
),

如上所述,您仍然需要为某些自定义(如自定义填充)快速添加自定义小部件.

Flutter相关问答推荐

如何使用底部导航栏修复此导航问题

来自FutureProvider的数据只打印两个不同的变量,它们对一个实例只有一次相同的值,为什么?

Flutter BLoC et workmanager:如何创建独特的仓库初始化模式?

查询满足AND条件的文档的FiRestore

try 使用fl_Chart of Ffltter,但在导入它时遇到以下错误:Error:';TextScaler';is;t a type

将记录/元组用作SplayTreeMap中的键

Flutter 中的 setState() 内部是如何工作的?

在 flutter 的列中使用 Expanded 时出现渲染 Flex 错误

无法应用插件com.chaquo.python

NotifierProvider 每次更新都会重新构建并且值不更新

Flutter:使用 GlobalKey 访问 BlocProvider

在参数为空时保持命名参数的默认值

点击按钮后重新启动定时器

如何使Flutter 屏幕无法关闭?

转换函数上传文件上传Uint8List

通过一个具体的例子理解Flutter约束的本质

如何限制用户每 24 小时执行的操作数?

更改文本字段Flutter 中最大字母的 colored颜色

阴影效果只出现在一张卡片的左边 在Flutter 中?

如何在Flutter 中将列表的模型类型转换为数组?