Flutter button, unwanted extra top and bottom padding

妖精的绣舞 提交于 2020-05-31 07:17:32

问题


I'm trying to customize a Flutter button:

ButtonTheme(
    child: FlatButton(
        child: Text(_text),
        color: _color,
        onPressed: _onPressed,
    ),
    minWidth: 40,
),

But I can't get rid of the extra top and bottom padding:

FlatButton, RaisedButton, MaterialButton, all of them have the padding.

NOTE: I have more customizations, such as padding, text trimming, and border-radius.


回答1:


To remove that padding add - materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,

ButtonTheme(
                            child: FlatButton(
                              materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,  // add this
                              child: Text('Dummy'),
                              color: Colors.blue,
                              onPressed: () {},
                            ),
                            minWidth: 40,
                          ),



回答2:


Set padding to 0 for your ButtonTheme like shown below

    new ButtonTheme(
      padding: new EdgeInsets.all(0.0),
      child: FlatButton(
        child: Text(_text),
        color: _color,
        onPressed: _onPressed,
        ),
      minWidth: 40,
    ),


来源:https://stackoverflow.com/questions/54938971/flutter-button-unwanted-extra-top-and-bottom-padding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!