关于 Flutter的Button按钮没有高度设置(新手)

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设置高度,宽度会占满

猜你喜欢

转载自juejin.im/post/5b85f1de6fb9a01a0f24a233