flutter 实战 之 按钮 ElevatedButton TextButton OutlineButton

简单好看的小清新风景图片2017 从你的全世界路过-腾牛个性网

ElevatedButton是一个带有阴影效果的Material Design风格的按钮,用于触发操作。以下是一些常用的属性:

  1. onPressed:按钮被点击时触发的回调函数。
  2. onLongPress:按钮被长按时触发的回调函数。
  3. style:按钮的样式,可以使用ElevatedButton.styleFrom()方法来设置样式,例如颜色、阴影、填充等。
  4. child:按钮的内容,可以是一个TextIcon或其他widget。
  5. focusNode:用于处理按钮的焦点状态。
  6. autofocus:布尔值,表示按钮是否自动获取焦点。
  7. clipBehavior:决定按钮的子部件在按钮边界内的渲染方式。

我们来看看一些按钮直接效果得区别和联系

实现代码如下:
 


class Page extends StatelessWidget {
  Page({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return ListView(children: [
      Column(
        mainAxisAlignment: MainAxisAlignment.spaceAround,
        children: [
          ElevatedButton(
              onPressed: () {
                print("普通按钮");
              },
              child: Text("this is a button")),
          TextButton(onPressed: () {}, child: Text("这是文本按钮")),
          OutlinedButton(onPressed: () {}, child: Text("边框按钮")),
          IconButton(onPressed: () {}, icon: Icon(Icons.add)),
          ElevatedButton.icon(
            style: ButtonStyle(
              backgroundColor: MaterialStateProperty.all(Colors.lightGreen),  // 背景颜色
              foregroundColor: MaterialStateProperty.all(Colors.white),   // 字体颜色
            ),
            onPressed: () {},
            icon: Icon(Icons.account_box),
            label: Text("文本图标按钮"),
          ),
          TextButton.icon(
            onPressed: () {},
            icon: Icon(Icons.ad_units_rounded),
            label: Text("接收"),
          ),
          OutlinedButton.icon(
            onPressed: () {},
            icon: Icon(Icons.baby_changing_station),
            label: Text("发送"),
          ),
        ],
      )
    ]);
  }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

wniuniu_

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

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

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

打赏作者

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

抵扣说明:

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

余额充值