我发现无法在扑动中设置提升按钮的宽度。如果我已经很好地理解了,我应该把提升按钮放入大小框中。然后,我将能够设置框的宽度或高度。正确吗?还有别的办法吗?

在每个按钮周围创建一个大小框有点乏味,所以我想知道为什么他们选择这样做。我很确定他们这么做有一个很好的理由,但我不这么认为。 对于初学者来说,脚手架很难阅读和构建。

new SizedBox(
  width: 200.0,
  height: 100.0,
  child: ElevatedButton(
    child: Text('Blabla blablablablablablabla bla bla bla'),
    onPressed: _onButtonPressed,
  ),
),

当前回答

SizedBox(
  width: double.infinity,
  child: ElevatedButton(
    child: Text("FULL WIDTH"),
    onPressed: () {},
  ),
),

使用ElevatedButton,因为RaisedButton已弃用

其他回答

你可以像他们在评论中说的那样做,或者你可以省下力气,使用RawMaterialButton。什么都有,你可以把边界变成圆形 还有很多其他属性。Ex形状(增加半径使形状更圆)

shape: new RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),//ex add 1000 instead of 25

你可以使用你想要的任何形状作为按钮,通过使用手势检测器,它是一个小部件,在子属性下接受另一个小部件。 就像在另一个例子中

GestureDetector(
onTap: () {//handle the press action here }
child:Container(

              height: 80,
              width: 80,
              child:new Card(

                color: Colors.blue,
                shape: new RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
                elevation: 0.0,                
              child: Icon(Icons.add,color: Colors.white,),
              ),
              )
)

我们也可以使用ElevatedButton Widget,它有fixedSize属性。最新Flutter版本

 ElevatedButton(
          onPressed: () {},
          style: ElevatedButton.styleFrom( 
              fixedSize: Size(120, 34), // specify width, height
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(
                20,
              ))),
          child: Text("Search"),
        )

预览

您不需要使用其他小部件来设置大小。你可以为ElevatedButton使用minimumSize

ElevatedButton(
              style: ElevatedButton.styleFrom(
                      minimumSize: const Size(200, 50),
                      elevation: 0,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(50), // <-- Radius
                      ),
                    ),
                    onPressed: (){},
                    child: const Text("Text", style: TextStyle(fontSize: 20, fontWeight: FontWeight.w500),),
                  ),

如果你想全局改变所有RaisedButtons的高度和minWidth,那么你可以在MaterialApp中覆盖ThemeData:

 @override
  Widget build(BuildContext context) {
    return MaterialApp(
       ...
       theme: ThemeData(
       ...
       buttonTheme: ButtonThemeData(
          height: 46,
          minWidth: 100,
       ),
    ));
  }

如文档中所述

凸起的按钮的最小尺寸为88.0 * 36.0 用ButtonTheme覆盖。

你可以这样做

ButtonTheme(
  minWidth: 200.0,
  height: 100.0,
  child: RaisedButton(
    onPressed: () {},
    child: Text("test"),
  ),
);