Flutter RaisedButton FlatButton OutlineButton ButtonBar

Flutter 系列文章 总体目录


RaisedButton、 FlatButton 、OutlineButton的区别

RaisedButton带阴影的按钮
FlatButton无阴影的按钮
OutlineButton带边框的按钮

效果如果:
在这里插入图片描述

1、RaisedButton

基本属性如下:

onPressed点击时触发,如果不设置此属性 Button为不可用状态 在这里插入图片描述
onHighlightChanged高亮变化回调,参数:是否高亮,按下时高亮,抬起不高亮,
textTheme字体theme,属性有:ButtonTextTheme.normal、ButtonTextTheme.accent、ButtonTextTheme.primary 在这里插入图片描述
textColor字体颜色
disabledTextColor禁用状态下字体颜色
color背景颜色
disabledColor禁用状态下背景颜色
highlightColor高亮颜色,按下时的颜色
splashColor水波纹颜色,按下松开会有水波纹效果
colorBrightness字体亮度 设置了textColor、color颜色,此值无效 在这里插入图片描述
elevation阴影z轴的值 ,注意看阴影在这里插入图片描述
highlightElevation高亮 阴影z轴的值
disabledElevation禁用阴影z轴的值
paddingpadding
shape形状,系统内置了很多shape 在这里插入图片描述 以Border为例:在这里插入图片描述
clipBehavior暂时想不到干什么的
materialTapTargetSize暂时想不到干什么的
animationDuration暂时想不到干什么的
child一般是Text

可以通过RaisedButton.icon设置一个icon

RaisedButton.icon(
            onPressed: () {},
            icon: Icon(Icons.access_alarm),
            label: Text('label')),

在这里插入图片描述

2、FlatButton

FlatButton的属性和RaisedButton一样

3、OutlineButton

borderSide边框样式 ,BorderStyle 样式如下在这里插入图片描述
disabledBorderColor禁用状态下边框颜色
highlightedBorderColor高亮状态下边框颜色

4、ButtonBar

ButtonBar 一横排的Button布局

alignment布局方向,默认MainAxisAlignment.end
mainAxisSize主轴大小,默认MainAxisSize.max
childrenButton集合

demo:

import 'package:flutter/material.dart';

class ButtonDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return Column(
      children: <Widget>[
        Row(
          children: <Widget>[
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('RaisedButton'),
            ),
            FlatButton(
              onPressed: () {},
              child: Text('FlatButton'),
            ),
            OutlineButton(
              onPressed: () {},
              color: Colors.red,
              child: Text('OutlineButton'),
            ),
          ],
        ),
        Row(
          children: <Widget>[
            OutlineButton(
              onPressed: () {},
              child: Text('none'),
              borderSide: BorderSide(color:Colors.green,width: 2.0,style: BorderStyle.none),
            ),
            OutlineButton(
              onPressed: () {},
              child: Text('solid'),
              borderSide: BorderSide(color:Colors.green,width: 2.0,style: BorderStyle.solid),
            ),
          ],
        ),
        Row(
          children: <Widget>[
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('onPressed'),
            ),
            RaisedButton(
              child: Text('not press'),
            ),
          ],
        ),
        Row(
          children: <Widget>[
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('normal'),
              textTheme: ButtonTextTheme.normal,
            ),
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('accent'),
              textTheme: ButtonTextTheme.accent,
            ),
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('primary'),
              textTheme: ButtonTextTheme.primary,
            ),
          ],
        ),
        Row(
          children: <Widget>[
            RaisedButton(
              child: Text('not press'),
              disabledColor: Colors.red,
            )
          ],
        ),
        Row(
          children: <Widget>[
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('darks'),
              colorBrightness: Brightness.dark,
            ),
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('light'),
              colorBrightness: Brightness.light,
            ),
          ],
        ),
        Row(

          children: <Widget>[
            RaisedButton(
                onPressed: (){print('onPressed');},
                child: Text('elevation=10'),
              elevation: 10,
            ),
          ],
        ),
        Row(
          children: <Widget>[
            RaisedButton(
              onPressed: (){print('onPressed');},
              child: Text('Border'),
              shape: Border.all(),
            ),
          ],
        ),
        Row(
          children: <Widget>[
            RaisedButton(
              onPressed: (){print('nonenonenonenonenone');},
              child: Text('nonenonenonenonenone'),
              clipBehavior: Clip.none,
            ),

            RaisedButton(
              onPressed: (){print('hardEdge');},
              child: Text('hardEdge'),
              clipBehavior: Clip.hardEdge,
            ),

          ],
        ),
        Row(
          children: <Widget>[
            RaisedButton(
              onPressed: (){print('antiAlias');},
              child: Text('antiAlias'),
              clipBehavior: Clip.antiAlias,
            ),
            RaisedButton(
              onPressed: (){print('antiAliasWithSaveLayer');},
              child: Text('antiAliasWithSaveLayer'),
              clipBehavior: Clip.antiAliasWithSaveLayer,
            ),
          ],
        ),

        RaisedButton.icon(
            onPressed: () {},
            icon: Icon(Icons.access_alarm),
            label: Text('label')
        ),
        Container(
          child: ButtonBar(
            children: <Widget>[
              RaisedButton(child: Text('ButtonBar'),),
              RaisedButton(child: Text('ButtonBar'),),
              RaisedButton(child: Text('ButtonBar'),),

            ],
          ),
        ),
      ],
    );
  }
}

整体效果:
在这里插入图片描述

交流

如果你对Flutter还有疑问或者技术方面的疑惑,欢迎加入Flutter交流群(微信:laomengit)。

同时也欢迎关注我的Flutter公众号【老孟程序员】,公众号首发Flutter的相关内容。

Flutter地址:http://laomengit.com 里面包含160多个组件的详细用法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

老孟Flutter

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值