flutter 里面 RaisedButton、FloatingActionButton、FlatButton、OutlineButton 中四个button都无高度设置,如下用RaisedButton举例:

处理办法第一种:没有高度就用一个有高度的 View 来加载 Container,于是有了
     new Container(
         height: 60.0,
         child: new RaisedButton(onPressed: (){},
           child: new Text("测试Buton的宽度"),
           color: Colors.deepOrange,
         ),
       ),

Container设置高度就实现 ,但是Container的宽度不会占满 只会随着里面字体的宽度显示。 接下来使用 pading 实现Button的高度

处理办法二,使用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设置高度,宽度会占满

转载于:https://www.cnblogs.com/Free-Thinker/p/10244251.html

Logo

开源鸿蒙跨平台开发社区汇聚开发者与厂商,共建“一次开发,多端部署”的开源生态,致力于降低跨端开发门槛,推动万物智联创新。

更多推荐