无法在Flutter中增加对话框框的宽度

7
我需要在我的应用程序中构建一个弹出对话框。我正在使用 Dialog 类,并将其包装在 SizedBox 类中以增加对话框的宽度。但是,对话框的宽度没有增加。如何增加它的宽度?

onTap: () {
showDialog(
    context: context,
    child:SizedBox(
        width: 900,
        child: Dialog(
            backgroundColor :Colors.white,
            insetAnimationDuration: const Duration(milliseconds: 10),
            shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
            child: Container(
                child: Column(
                    children: <Widget>[
                        Text('hello'),
                        FlatButton(
                        onPressed: () {
                            Navigator.of(context).pop();
                        },
                        child: new Text("OK"),
                        ),
                    ]
                ),
            ),  
        ),
    ),
);
},


如果您能提供一个代码示例,展示您已经尝试过的内容,那将非常有帮助! - NiklasPor
@Niklas,我的代码非常长。我已经编辑了我的帖子,并且在帖子中给出的代码部分是用于对话框的。 - Juthi Sarker Aka
尝试将SizedBox放置在Dialog内部。 - Kirill Matrosov
1个回答

8

试试这个

showDialog(
  context: context,
  builder: (context) {
    return Dialog(
      backgroundColor: Colors.white,
      insetAnimationDuration: const Duration(milliseconds: 100),
      shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(20)),
      child: Container( // use container to change width and height
        height: 200,
        width: 400,
        child: Column(
          children: <Widget>[
            Text('hello'),
            FlatButton(
              onPressed: () {
                Navigator.of(context).pop();
              },
              child: new Text("OK"),
            ),
          ],
        ),
      ),
    );
  },
);

我将withchild参数更改为builder,因为child已过时。

它与屏幕边界有一定距离,因此无法覆盖整个屏幕,但可以覆盖到一定限度。


2
谢谢!@Chetan Pawar。我尝试了你的代码。它有效! - Juthi Sarker Aka
我想创建一个固定尺寸为150 x 150像素的showDialog。我已经更新了容器的宽度和高度,如下所示: return Container(height: 150, width: 150,); 但仍然不起作用。我得到的是3:2比例的矩形框而不是正方形。有什么建议吗? - Kamlesh

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接