美文网首页
【Flutter】Button

【Flutter】Button

作者: diva_dance | 来源:发表于2019-03-20 11:42 被阅读0次

初始状态下的按钮(背景色是绿色)


image

MaterialButton

image
new MaterialButton(

  color: Colors.blue,

  textColor: Colors.white,

  onPressed: _onPressed,

  child: new Text('button'),

)

一般来说,如果需要点击事件,就要嵌套一个 Button,因为 Container、Text 等组件都没有点击事件。

默认是透明背景。

FlatButton

image
new FlatButton(
    color: Colors.blue,
    textColor: Colors.white,
    onPressed: _onPressed,
    child: new Text('FlatButton'),
)

和 MaterialButton 类似,可用于通用功能,更具有可读性。

RaisedButton

image
new RaisedButton(
  onPressed: _onPressed,
  child: new Text('RaisedButton'),
),

和 MaterialButton 类似,有默认的背景颜色,更具有强调性。

IconButton

image
 new IconButton(
    onPressed: _onPressed,
    color: Colors.red,
    icon: new Icon(Icons.star),
    padding: const EdgeInsets.all(12.0)
),

有图标的 Button ,没有默认的颜色,无法设置背景颜色, padding 默认是 12 。方便选中button 。

FloatingActionButton

image
new FloatingActionButton(
  onPressed: _onPressed,
  child: new Icon(Icons.star),
  backgroundColor: Colors.blue
),

有默认的背景色是蓝色,在 Scaffold 里使用的时候,它是一个浮动状态的按钮,在其他地方使用,就不会浮动了。

ButtonBar

image button 的容器,可以让 button 在同一条直线上面。默认居右。 image.png

相关文章

网友评论

      本文标题:【Flutter】Button

      本文链接:https://www.haomeiwen.com/subject/lwknmqtx.html