dart 在 Flutter 升高按钮中设置宽度

pn9klfpd  于 2023-06-19  发布在  Flutter
关注(0)|答案(3)|浏览(189)

我怎么能在flutter elevatedbutton中设置宽度,这是我的代码,谢谢

ElevatedButton(
                              style: ButtonStyle(
                                  shape: MaterialStateProperty.all<
                                          RoundedRectangleBorder>(
                                      RoundedRectangleBorder(
                                          borderRadius:
                                              BorderRadius.circular(18.0),
                                              
                                          side: BorderSide()))),
                              onPressed: () {},
                              child: Text(
                                "Baca",
                                style: TextStyle(color: Colors.white),
                              ),
                            ),
h4cxqtbf

h4cxqtbf1#

将其 Package 在Container中,因此子节点也获得父节点的大小。

Container(
      width: 400,
      child: ElevatedButton(
        
        style: ButtonStyle(
            shape: MaterialStateProperty.all<RoundedRectangleBorder>(
                RoundedRectangleBorder(
                    borderRadius: BorderRadius.circular(18.0),
                    side: BorderSide()))),
        onPressed: () {},
        child: const Text(
          "Baca",
          style: TextStyle(color: Colors.white),
        ),
      ),
    );
0vvn1miw

0vvn1miw2#

请尝试以下ElevatedButton宽度和高度的答案:

ElevatedButton(
    onPressed: () {},
    child: Text("Ok"),
    style: ElevatedButton.styleFrom(
        //change width and height on your need width = 200 and height = 50
    minimumSize: Size(200, 50),
    ),
),
atmip9wb

atmip9wb3#

最好像这样使用SizedBox

SizedBox(
  width: 200,
  child: ElevatedButton(
    style: ButtonStyle(
      shape: MaterialStateProperty.all<RoundedRectangleBorder>(
        RoundedRectangleBorder(
          borderRadius: BorderRadius.circular(18.0),
          side: BorderSide()
        )
      )
    ),
    onPressed: () {},
    child: const Text(
      "Baca",
      style: TextStyle(color: Colors.white),
    ),
  ),
);

相关问题