flutter Material3警报对话框操作未居中

brgchamk  于 2023-11-21  发布在  Flutter
关注(0)|答案(4)|浏览(126)

我正在制作一个带有2个按钮的警报对话框,在material2中,alertdialog的对齐工作正常,两个按钮居中,但一旦我更新到material3版本,两个按钮都对齐到右侧,添加actionsalign并没有解决问题或移动按钮。
我想“用相机扫描”和“从图像读取”按钮将水平居中。代码:

AlertDialog(
      actionsAlignment: MainAxisAlignment.center,
      alignment: Alignment.bottomCenter,
      actions: [
        Text("Testing"),
        // scan with camera
        TextButton(
            onPressed: () {
            },
            child: Text("Scan with Camera")),
        // read from image
        TextButton(
            onPressed: () {
            },
            child: Text("Read from image"))
      ],
    ))

字符串

zysjyyx4

zysjyyx41#

默认情况下,actionsOverflowAlignment使用OverflowBarAlignment.end

AlertDialog(
   actionsOverflowAlignment: OverflowBarAlignment.center,

字符串

elcex8rz

elcex8rz2#

试试这个

AlertDialog(
                    content: Column(
                      mainAxisAlignment: MainAxisAlignment.center,
                      mainAxisSize: MainAxisSize.min,
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        Text('Testing'),
                     
                        TextButton(
                          onPressed: () {
                    
                          },
                          child: Text('Scan with Camera'),
                        ),
          
                        TextButton(
                          onPressed: () {
                      
                          },
                          child: Text('Read from image'),
                        ),
                      ],
                    ),
                  );

字符串

hgb9j2n6

hgb9j2n63#

请尝试使用actionsOverflowAlignment: OverflowBarAlignment.center,如下代码所示:

AlertDialog(
          actionsOverflowAlignment: OverflowBarAlignment.center,
          actionsAlignment: MainAxisAlignment.center,
          alignment: Alignment.bottomCenter,
          actions: [
            const Text("Testing"),
            // scan with camera
            TextButton(
                onPressed: () {}, child: const Text("Scan with Camera")),
            // read from image
            TextButton(
                onPressed: () {}, child: const Text("Read from image"))
          ],
        ),

字符串

nimxete2

nimxete24#

你正在添加窗口小部件的行动是左对齐尝试添加你的窗口小部件内容属性像这样

AlertDialog(
        title: const  Text("Testing"), // dialog title
        content: const SingleChildScrollView(
          child: ListBody(
            children: <Widget>[
             
        // scan with camera
        TextButton(
            onPressed: () {
            },
            child: Text("Scan with Camera")),
        // read from image
        TextButton(
            onPressed: () {
            },
            child: Text("Read from image"))
            ],
          ),
        ),
)

字符串

相关问题