1. /*
  2. Flutter中的常见的按钮组件 以及自定义按钮组件
  3. 一、Flutter中的按钮组件介绍
  4. Flutter里有很多的Button组件,常见的按钮组件有:RaisedButton/FlatButton/IconButton/
  5. OutlineButton/ButtonBar/FloatingActionButton等。
  6. RaisedButton:凸起的按钮,其实就是Material Design风格的Button
  7. FlatButton:扁平化的按钮
  8. OutlineButton:线框按钮
  9. IconButton:图标按钮
  10. ButtonBar: 按钮组
  11. FloatingActionButton:浮动按钮
  12.  
  13. 二、Flutter按钮组件中的一些属性:
  14. onPressed:必填参数,按下按钮时触发的回调,接受一个方法,传null表示按钮禁用,会显示禁用相关样式
  15. child:文本控件
  16. textColor:文本颜色
  17. color:按钮的颜色
  18. disabledColor:按钮禁用时的颜色
  19. disabledTextColor:按钮禁用时的文本颜色
  20. splashColor:点击按钮时水波纹的颜色
  21. elevation:阴影的范围
  22. padding:内边距
  23. shape:设置按钮的形状
  24. */

Button.dart

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

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

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

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

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

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

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

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

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

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

  5. 常用样式制作思路 自定义按钮~自适应布局~常见bug seajs简记 初学者必知的HTML规范 不容忽略的——CSS规范

    常用样式制作思路   学习常用样式总结参考来自这里 带点文字链接列表利用:before实现 1 <!DOCTYPE html> 2 <html lang="en" ...

  6. 如何让antd的Modal组件的确认和取消不显示(或自定义按钮)(转载)

    使用Modal中的footer属性,如下: <Modal title="更改成员" visible={visible} confirmLoading={confirmLoad ...

  7. PyQt(Python+Qt)学习随笔:Designer中的QDialogButtonBox增加自定义按钮的方法

    在Qt Designer中可以预先定义标准按钮,相关支持的标准按钮请见<PyQt(Python+Qt)学习随笔:Designer中的QDialogButtonBox的StandardButton ...

  8. 基于React.js网页版弹窗|react pc端自定义对话框组件RLayer

    基于React.js实现PC桌面端自定义弹窗组件RLayer. 前几天有分享一个Vue网页版弹框组件,今天分享一个最新开发的React PC桌面端自定义对话框组件. RLayer 一款基于react. ...

  9. iOS开发——UI进阶篇(十八)核心动画小例子,转盘(裁剪图片、自定义按钮、旋转)图片折叠、音量震动条、倒影、粒子效果

    一.转盘(裁剪图片.自定义按钮.旋转) 1.裁剪图片 将一张大图片裁剪为多张 // CGImageCreateWithImageInRect:用来裁剪图片 // image:需要裁剪的图片 // re ...

随机推荐

  1. 脚本shell

    vim删除以#,空格开头的行   1,删除以#号开头的行: :g/^#/d :%s/^#.*\n 2,删除以空格开头的行: :g/^\s/d                “\s代表空格” :%s/^ ...

  2. Vue实现一个图片懒加载插件(转载)

    Vue是可以自定义指令的,最近学习过程中遇见了一个需要图片懒加载的功能,最后参考了别人的代码和思路自己重新写了一遍.以下将详细介绍如何实现自定义指令v-lazyload. 先看如何使用这个指令: &l ...

  3. 05-Docker私有仓库

    一.介绍私有仓库顾名思义,如果我们不想把docker镜像公开放到公有仓库中,只想在部门或团队内部共享docker镜像,这时私有仓库就来了. 二.私有仓库搭建与配置1.拉取私有仓库镜像,这里说明一下,私 ...

  4. 源码安装mongoDB

    1.安装启动 下载源码包,官方地址: wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel62-3.4.22.tgz 解压 ...

  5. Vue.js-组件化前端开发新思路

    Vue.js-组件化前端开发新思路 12017.04.14 18:31:25字数 6228阅读 5632 本文章是我最近在公司的一场内部分享的内容.我有个习惯就是每次分享都会先将要分享的内容写成文章. ...

  6. dumpe/dumpe2fs/e2fsck

    xt2/3/4文件系统备份工具 导出ext2/ext3/ext4文件系统信息 dumpe2fs e2fsck 强制检查文件系统 检查文件系统

  7. GitHub中PR(Pull request)操作

    1. 贡献代码: 贡献代码,通俗的说,就是自己修改了代码,希望合并到别人的Repository(仓库)中.将自己的智慧贡献给开源社区.下面将详细讲解步骤 1.1 第一步:fork 在GitHub社区闲 ...

  8. visual studio2015窗体中控件的属性中文说明不见了

    右击属性窗口,然后选中好说明就ok了.

  9. C++类*类型和其他类型相互转换

    类类型转换时会出现两种之间转换,下面我们说的是类类型 1.其他类型转换为本类类型 通过类带一个参数的构造函数:或者多个参数构造函数,除了第一个参数后面参数都有默认值时!这样在其他类型赋值给该类类型对象 ...

  10. python 时间等待

    #coding=utf- import time t1=time.time() time.sleep() t2=time.time() print(t2-t1) 输出 3.00304102898