一,概述
flutter 里面 RaisedButton、FloatingActionButton、FlatButton、OutlineButton 中四個button都無高度和寬度設置。
二,實現方法
- 第一種方法:沒有高度,寬度就用一個有高度的 View 來加載 Container,
new Container( height: 60.0,
width:60.0, child: new RaisedButton(onPressed: (){}, child: new Text("測試Buton的寬度"), color: Colors.deepOrange, ), ),
-
第二種方法,使用pading來實現 Button的高度
new Padding(padding: new EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 20.0), child: new Row( children: <Widget>[ new Expanded(child: new RaisedButton(onPressed: (){ print(" 我點擊了 Padding 下的 RaisedButton"); }, //通過控制 Text 的邊距來控制控件的高度 child: new Padding(padding: new EdgeInsets.fromLTRB(10.0, 10.0, 0.0, 10.0), child: new Text("Padding測試Buton的寬度"), ), color: Colors.deepOrange, ), ), ], ), ),
注意:pading設置高度,寬度會占滿