Flutter小技巧总结之关于 Flutter的Button按钮设置高度,和宽度


 

一,概述  

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM