在Flutter ElevatedButton中设置宽度。

3
如何在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),
    ),
)
3个回答

6

将其包装在 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),
        ),
      ),
    );

2
尝试以下答案来设置的宽度和高度:
ElevatedButton(
    onPressed: () {},
    child: Text("Ok"),
    style: ElevatedButton.styleFrom(
        //change width and height on your need width = 200 and height = 50
    minimumSize: Size(200, 50),
    ),
),

0
最好使用这样的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),
    ),
  ),
);

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