【问题标题】:Flutter & AlertDialog : How to stretch a container so that it has the same width with the AlertDialog box?Flutter & AlertDialog : 如何拉伸容器使其与 AlertDialog 框具有相同的宽度?
【发布时间】:2021-01-02 21:33:32
【问题描述】:

我一直在尝试在 Flutter 的 AlertDialog 框中创建一个按钮。但我找不到拉伸按钮容器的方法。请检查我的代码并查看下面的示例图片。

AlertDialog(
                    title: Center(child: Text("Picture")),
                    content: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: <Widget>[
                        Container(
                          width: width,
                          //height: height,
                          child: FadeInImage.memoryNetwork(
                            placeholder: kTransparentImage,
                            image: image.url,
                          ),
                        ),
                        SizedBox(
                          height: 10,
                        ),
                        InkWell(
                          onTap: () {
                            Navigator.pop(context);
                          },
                          child: Container(
                            alignment: Alignment.center,
                            height: 50,
                            width: width,
                            color: primaryColor,
                            child: Text(
                              'Okay',
                              style: TextStyle(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                        ),
                      ],
                    ),
                  );

请帮助我。我期待听到您的意见。提前谢谢你。

【问题讨论】:

    标签: flutter dart flutter-alertdialog


    【解决方案1】:

    AlertDialogAlertDialog 的右侧、左侧和底部有一个default content padding24 逻辑像素,以将内容与对话框的其他边缘分开。..

    要使Button 适合AlertDialog 宽度,您需要将zero 中的AlertDialog 指定为padding,并将paddings 应用于除Button 之外的其他小部件。

    我使用您的代码添加了一个示例:


    
         AlertDialog(
                        // change the default padding to zero
                        contentPadding: EdgeInsets.zero,
                        title: Center(child: Text("Picture")),
                        content: Column(
                          mainAxisSize: MainAxisSize.min,
                          children: <Widget>[
                             // wrap your container with a padding widget
                             Padding(
                             padding: const EdgeInsets.all(20.0), // give a preferred padding
                             child: Container(
                             width: width,
                             //height: height,
                             placeholder: kTransparentImage,
                             image: image.url,
                                ),
                               ),
                              ),
                            SizedBox(
                              height: 10,
                            ),
                            InkWell(
                              onTap: () {
                                Navigator.pop(context);
                              },
                              child: Container(
                                alignment: Alignment.center,
                                height: 50,
                                width: width,
                                color: primaryColor,
                                child: Text(
                                  'Okay',
                                  style: TextStyle(
                                      color: Colors.white,
                                      fontWeight: FontWeight.bold),
                                ),
                              ),
                            ),
                          ],
                        ),
                      );
    

    【讨论】:

      猜你喜欢
      • 2019-05-23
      • 1970-01-01
      • 1970-01-01
      • 2019-12-04
      • 2012-10-29
      • 2013-12-28
      • 2021-08-26
      • 2020-09-26
      • 2015-08-01
      相关资源
      最近更新 更多