Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton、FlatButton、

IconButton、OutlineButton、ButtonBar、FloatingActionButton 等。

RaisedButton :凸起的按钮,其实就是 Material Design 风格的 Button FlatButton :扁平化的按钮
OutlineButton:线框按钮
IconButton :图标按钮

ButtonBar:按钮组
FloatingActionButton:浮动按钮


Flutter 按钮组件中的一些属性

属性名称

值类型

属性值

onPressed

VoidCallback ,一般接收一个 方法

必填参数,按下按钮时触发的回调,接收一个 方法,传 null 表示按钮禁用,会显示禁用相关 样式

child

Widget

文本控件

textColor

Color

文本颜色

color

Color

按钮的颜色

  1. disabledColor

Color

按钮禁用时的颜色

  1. disabledTextColor

Color

按钮禁用时的文本颜色

splashColor

Color

点击按钮时水波纹的颜色

  1. highlightColor

Color

  1. 点击(长按)按钮后按钮的颜色

elevation

double

  1. 阴影的范围,值越大阴影范围越大

padding

 

内边距

shape

 

设置按钮的形状

shape: RoundedRectangleBorder(

  1. borderRadius:
  2. BorderRadius.circular(10),
  3. )
  1. shape: CircleBorder(
  2. side: BorderSide(
  1. color: Colors.white,
  2. )

)

  1. import 'package:flutter/material.dart';
  2.  
  3. class ButtonDemoPage extends StatelessWidget {
  4. const ButtonDemoPage({Key key}) : super(key: key);
  5.  
  6. @override
  7. Widget build(BuildContext context) {
  8. return Scaffold(
  9. appBar: AppBar(
  10. title: Text("按钮演示页面"),
  11. actions: <Widget>[
  12. IconButton(
  13. icon: Icon(Icons.settings),
  14. onPressed: (){
  15.  
  16. },
  17. )
  18. ],
  19. ),
  20. body: Column(
  21. mainAxisAlignment: MainAxisAlignment.center,
  22. children: <Widget>[
  23. Row(
  24. mainAxisAlignment: MainAxisAlignment.center,
  25. children: <Widget>[
  26. RaisedButton(
  27. child: Text('普通按钮'),
  28. onPressed: () {
  29. print("普通按钮");
  30. },
  31. ),
  32. SizedBox(width: 5),
  33. RaisedButton(
  34. child: Text('颜色按钮'),
  35. color: Colors.blue,
  36. textColor: Colors.white,
  37. onPressed: () {
  38. print("有颜色按钮");
  39. },
  40. ),
  41. SizedBox(width: 5),
  42. RaisedButton(
  43. child: Text('阴影按钮'),
  44. color: Colors.blue,
  45. textColor: Colors.white,
  46. elevation: 20,
  47. onPressed: () {
  48. print("有阴影按钮");
  49. },
  50. ),
  51. SizedBox(width: 5),
  52. RaisedButton.icon(
  53. icon: Icon(Icons.search),
  54. label: Text('图标按钮'),
  55. color: Colors.blue,
  56. textColor: Colors.white,
  57. // onPressed: null,
  58. onPressed: () {
  59. print("图标按钮");
  60. })
  61. ],
  62. ),
  63. SizedBox(height: 10),
  64. Row(
  65. mainAxisAlignment: MainAxisAlignment.center,
  66. children: <Widget>[
  67. Container(
  68. height: 50,
  69. width: 400,
  70. child: RaisedButton(
  71. child: Text('宽度高度'),
  72. color: Colors.blue,
  73. textColor: Colors.white,
  74. elevation: 20,
  75. onPressed: () {
  76. print("宽度高度");
  77. },
  78. ),
  79. )
  80. ],
  81. ),
  82. SizedBox(height: 10),
  83. Row(
  84. mainAxisAlignment: MainAxisAlignment.center,
  85. children: <Widget>[
  86. Expanded(
  87. child: Container(
  88. height: 60,
  89. margin: EdgeInsets.all(10),
  90. child: RaisedButton(
  91. child: Text('自适应按钮'),
  92. color: Colors.blue,
  93. textColor: Colors.white,
  94. elevation: 20,
  95. onPressed: () {
  96. print("自适应按钮");
  97. },
  98. ),
  99. ),
  100. )
  101. ],
  102. ),
  103. SizedBox(height: 10),
  104. Row(
  105. mainAxisAlignment: MainAxisAlignment.center,
  106. children: <Widget>[
  107. RaisedButton(
  108. child: Text('圆角按钮'),
  109. color: Colors.blue,
  110. textColor: Colors.white,
  111. elevation: 20,
  112. shape: RoundedRectangleBorder(
  113. borderRadius: BorderRadius.circular(10)),
  114. onPressed: () {
  115. print("圆角按钮");
  116. }),
  117. Container(
  118. height: 80,
  119. child: RaisedButton(
  120. child: Text('圆形按钮'),
  121. color: Colors.blue,
  122. textColor: Colors.white,
  123. elevation: 20,
  124. splashColor: Colors.red,
  125. shape:
  126. CircleBorder(side: BorderSide(color: Colors.white)),
  127. onPressed: () {
  128. print("圆形按钮");
  129. }),
  130. ),
  131. FlatButton(
  132. child: Text("按钮"),
  133. color: Colors.blue,
  134. textColor: Colors.yellow,
  135. onPressed: () {
  136. print('FlatButton');
  137. },
  138. ),
  139. SizedBox(width: 10),
  140. OutlineButton(
  141. child: Text("按钮"),
  142. // color: Colors.red, //没有效果
  143. // textColor: Colors.yellow,
  144. onPressed: () {
  145. print('FlatButton');
  146. })
  147. ],
  148. ),
  149. SizedBox(height: 10),
  150. Row(
  151. mainAxisAlignment: MainAxisAlignment.center,
  152. children: <Widget>[
  153. Expanded(
  154. child: Container(
  155. margin: EdgeInsets.all(20),
  156. height: 50,
  157. child: OutlineButton(child: Text("注册"), onPressed: () {}),
  158. ),
  159. )
  160. ],
  161. ),
  162. Row(
  163. mainAxisAlignment: MainAxisAlignment.end,
  164. children: <Widget>[
  165. ButtonBar(
  166. children: <Widget>[
  167.  
  168. RaisedButton(
  169. child: Text('登录'),
  170. color: Colors.blue,
  171. textColor: Colors.white,
  172. elevation: 20,
  173. onPressed: () {
  174. print("宽度高度");
  175. },
  176. ),
  177. RaisedButton(
  178. child: Text('注册'),
  179. color: Colors.blue,
  180. textColor: Colors.white,
  181. elevation: 20,
  182. onPressed: () {
  183. print("宽度高度");
  184. },
  185. ),
  186. MyButton(text: "自定义按钮",height: 60.0,width: 100.0,pressed: (){
  187. print('自定义按钮');
  188. })
  189.  
  190. ],
  191. )
  192. ],
  193. )
  194. ],
  195. ));
  196. }
  197. }
  198.  
  199. //自定义按钮组件
  200.  
  201. class MyButton extends StatelessWidget {
  202. final text;
  203. final pressed;
  204. final width;
  205. final height;
  206. const MyButton({this.text='',this.pressed=null,this.width=80,this.height=30}) ;
  207.  
  208. @override
  209. Widget build(BuildContext context) {
  210. return Container(
  211. height: this.height,
  212. width: this.width,
  213. child: RaisedButton(
  214. child: Text(this.text),
  215. onPressed:this.pressed ,
  216. ),
  217. );
  218. }
  219. }

Flutter 中的常见的按钮组件 以及自定义按钮组件的更多相关文章

  1. 22Flutter中的常见的按钮组件 以及自定义按钮组件

    /* Flutter中的常见的按钮组件 以及自定义按钮组件 一.Flutter中的按钮组件介绍 Flutter里有很多的Button组件,常见的按钮组件有:RaisedButton/FlatButto ...

  2. echarts 显示下载按钮,echarts 自定义按钮,echarts 添加按钮

    echarts 显示下载按钮,echarts 自定义按钮,echarts 添加按钮 >>>>>>>>>>>>>>&g ...

  3. #003 React 组件 继承 自定义的组件

    主题:React组件 继承 自定义的 组件 一.需求说明 情况说明: 有A,B,C,D 四个组件,里面都有一些公用的逻辑,比如 设置数据,获取数据,有某些公用的的属性,不想在 每一个 组件里面写这些属 ...

  4. Flutter 中的常见的按钮组件 以及自 定义按钮组件

    一.Flutter 中的按钮组件介绍   Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton.FlatButton.   IconButton.Outlin ...

  5. Flutter中的普通路由与命名路由(Navigator组件)

    Flutter 中的路由通俗的讲就是页面跳转.在 Flutter 中通过 Navigator 组件管理路由导航.并提供了管理堆栈的方法.如:Navigator.push 和 Navigator.pop ...

  6. Flutter中的日期、格式化日期、日期选择器组件

    Flutter中的日期和时间戳 //獲取當前日期 DateTime _nowDate = DateTime.now(); print(_nowDate);//2019-10-29 10:57:20.3 ...

  7. MIP组件开发 自定义js组件开发步骤

    什么是百度MIP? MIP(Mobile Instant Pages - 移动网页加速器)主要用于移动端页面加速 官网参考:https://www.mipengine.org/doc/00-mip-1 ...

  8. flutter中的按钮组件

    Flutter 里有很多的 Button 组件很多,常见的按钮组件有:RaisedButton.FlatButton.IconButton.OutlineButton.ButtonBar.Floati ...

  9. Flutter 中的路由

    Flutter 中的路由通俗的讲就是页面跳转.在 Flutter 中通过 Navigator 组件管理路由导航. 并提供了管理堆栈的方法.如:Navigator.push 和 Navigator.po ...

随机推荐

  1. 局部敏感哈希算法(Locality Sensitive Hashing)

    from:https://www.cnblogs.com/maybe2030/p/4953039.html 阅读目录 1. 基本思想 2. 局部敏感哈希LSH 3. 文档相似度计算 局部敏感哈希(Lo ...

  2. Spring4- 01 - Spring框架简介及官方压缩包目录介绍- Spring IoC 的概念 - Spring hello world环境搭建

    一. Spring 框架简介及官方压缩包目录介绍 主要发明者:Rod Johnson 轮子理论推崇者: 2.1 轮子理论:不用重复发明轮子. 2.2 IT 行业:直接使用写好的代码. Spring 框 ...

  3. JDK源码那些事儿之ConcurrentLinkedQueue

    阻塞队列的实现前面已经讲解完毕,今天我们继续了解源码中非阻塞队列的实现,接下来就看一看ConcurrentLinkedQueue非阻塞队列是怎么完成操作的 前言 JDK版本号:1.8.0_171 Co ...

  4. PHP——封装Curl请求方法支持POST | DELETE | GET | PUT 等

    前言 Curl:  https://www.php.net/manual/en/book.curl.php curl_setopt: https://www.php.net/manual/en/fun ...

  5. 织梦dedecms会员中心分类管理无法修改、删除分类名

    member/mtypes.PHP 文件中添加 另外,member/myfriend_group.php文件中也存在同样的问题,也要添加,不添加的话好友分组中也是同样问题

  6. netty: 编解码之jboss marshalling, 用marshalling进行对象传输

    jboss marshalling是jboss内部的一个序列化框架,速度也十分快,这里netty也提供了支持,使用十分方便. TCP在网络通讯的时候,通常在解决TCP粘包.拆包问题的时候,一般会用以下 ...

  7. Error Permission denied when running brew cleanup

    Error Permission denied when running brew cleanup When I try to run `brew cleanup` I get: Warning: S ...

  8. vue组件传值的三种方式,文字版解释

    父传子: 当子组件子父组件中当标签使用的时候,给子组件添加一个自定义属性,值为需要传递的值(如: <Child v-bind:parentToChild="parentMsg" ...

  9. 行列式的组合定义及其应用--反对称阵的Pfaffian

    以组合定义为出发点的行列式理论的引入方式在很多高等代数或线性代数的教材中被采用, 其优缺点同样明显. 组合定义形式上的简单是其最大的优点, 用它可以简洁地证明行列式的所有性质, 并快速进入行列式的计算 ...

  10. [golang]A modern, fast and scalable websocket framework with elegant API written in Go

    A modern, fast and scalable websocket framework with elegant API written in Go http://bit.ly/neffos- ...