Flutter Button 图文分析、效果浏览

题记:不到最后时刻,千万别轻言放弃,无论结局成功与否,只要你拼博过,尽力过,一切问心无愧


本文章首发于微信公众号(biglead) 我的大前端生涯 ,同步刊登各技术论坛。

【x1】微信公众号的每日提醒 随时随记 每日积累 随心而过

【x2】各种系列的视频教程 免费开源 关注 你不会迷路

【x3】系列文章 百万 Demo 随时 复制粘贴 使用


1 Flutter 提供的Button比较多

  Widget buildRaisedButton(){
    //它默认带有阴影和灰色背景。按下后,阴影会变大
    return RaisedButton(
      child: Text("RaisedButto"),
      onPressed: () => {},
    );
  }

在这里插入图片描述



  Widget buildFlatButton(){
    //FlatButton即扁平按钮,默认背景透明并不带阴影。按下后,会有背景色:
    return FlatButton(
      child: Text("登录"),
      onPressed: () => {},
    );
  }

在这里插入图片描述


  Widget buildOutlineButton(){
    //OutlineButton默认有一个边框,不带阴影且背景透明。按下后,边框颜色会变亮、同时出现背景和阴影(较弱):
    return OutlineButton(
      child: Text("登录"),
      onPressed: () => {},
    );
  }

在这里插入图片描述


  Widget buildIconButton(){
    return IconButton(
      icon: Icon(Icons.thumb_up),
      onPressed: () => {},
    );
  }

在这里插入图片描述

2 为FlatButton设置一个圆角背景

在这里插入图片描述

  Widget buildCustomButton(){
    return FlatButton(
      //按钮文字颜色
      textColor: Colors.white,
      //按钮禁用时的背景颜色
      disabledColor:Colors.grey,
      //按钮禁用时的文字颜色
      disabledTextColor: Colors.grey,
      //正常状态下的背景颜色
      color: Colors.blue,
      //按钮按下时的背景颜色
      highlightColor: Colors.blue[700],
      //按钮主题,默认是浅色主题
      colorBrightness: Brightness.dark,
      //外形
      splashColor: Colors.grey,
      // button 显示的文字
      child: Text("Submit"),
      //圆角边框
      shape:RoundedRectangleBorder(borderRadius: BorderRadius.circular(20.0)),
      //按钮点击回调
      onPressed: () => {},
    );
  }


【1】 目前在西瓜视频上免费刊登 Flutter 系列教程,每日更新,欢迎关注接收提醒点击查看提示

在这里插入图片描述


【2】 本公众号会首发系列专题文章,付费的视频课程会在公众号中免费刊登,在你上下班的路上或者是睡觉前的一刻,本公众号都是你浏览知识干货的一个小选择,收藏不如行动,在那一刻,公众号会提示你该学习了。
在这里插入图片描述

Flutter中,ButtonStyle是用来自定义按钮样式的一个类。通过使用ButtonStyle,你可以修改按钮的背景颜色、文本样式、边框等属性,以创建自己需要的按钮样式。ButtonStyle可以应用于多种类型的按钮,比如ElevatedButton、TextButton和IconButton等。\[1\] 举个例子,如果你想创建一个自定义的ElevatedButton,你可以使用ButtonStyle来设置按钮的背景颜色、文本样式等。下面是一个使用ButtonStyle的示例代码: ```dart ElevatedButton( onPressed: () {}, child: Text('Custom Button'), style: ButtonStyle( backgroundColor: MaterialStateProperty.all<Color>(Colors.blue), textStyle: MaterialStateProperty.all<TextStyle>(TextStyle(color: Colors.white)), // 其他样式属性 ), ) ``` 在上面的代码中,我们通过ButtonStyle的backgroundColor属性设置了按钮的背景颜色为蓝色,通过textStyle属性设置了按钮文本的颜色为白色。你还可以根据需要设置其他样式属性,比如边框、阴影等。 除了ElevatedButton,你也可以在TextButton和IconButton中使用ButtonStyle来自定义按钮样式。例如,下面是一个使用ButtonStyle的TextButton的示例代码: ```dart TextButton( onPressed: () {}, child: Text('Custom TextButton'), style: ButtonStyle( foregroundColor: MaterialStateProperty.all<Color>(Colors.red), // 其他样式属性 ), ) ``` 总结起来,ButtonStyle是一个用于自定义按钮样式的类,可以应用于多种类型的按钮。通过设置ButtonStyle的各种属性,你可以轻松地创建自己需要的按钮样式。\[2\]\[3\] #### 引用[.reference_title] - *1* *2* [【Flutter】关于Button 的那些知识ElevatedButton等,以及Buttonstyle](https://blog.csdn.net/weixin_43444734/article/details/128582374)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Flutter TextButton 详细使用配置、Flutter ButtonStyle样式概述实践](https://blog.csdn.net/zl18603543572/article/details/109545733)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

早起的年轻人

创作源于分享

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

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

打赏作者

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

抵扣说明:

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

余额充值