小工具知识网

当前位置: 首页 > 行业知识 > Flutter开发之——基本组件-Button

行业知识

Flutter开发之——基本组件-Button

2026-10-30 18:53:14 来源:互联网转载

自定义Material Button使用RawMaterialButton

2.3 单纯图标

  • IconButton

2.4 下拉按钮

  • DropdownButton

2.5 悬浮按钮

  • FloatingActionButton

三 按钮常用方法


flutter中的Button基本上都是继承MaterialButton,先来看看MaterialButton中的属性

const MaterialButton({

Key key,

@required this.onPressed, //按下事件

this.onLongPress, //长按事件

this.onHighlightChanged, //水波纹高亮变化回调

this.mouseCursor, //鼠标指针的光标进入或悬停在此按钮的[InkWell]上时。

this.textTheme, //按钮的主题

this.textColor, //文字的颜色

this.disabledTextColor, //按钮禁用时候文字的颜色

this.color, //按钮的背景颜色

this.disabledColor, //按钮禁用的背景颜色

this.focusColor, //获取焦点的颜色

this.hoverColor, //悬停颜色

this.highlightColor, //点击或者toch控件高亮的时候显示在控件上面,水波纹下面的颜色

this.splashColor, //水波纹的颜色

this.colorBrightness, //按钮主题高亮

this.elevation, //按钮下面的阴影

this.focusElevation, //获取焦点的阴影

this.hoverElevation, //悬停的阴影

this.highlightElevation, //高亮时候的阴影

this.disabledElevation, //未设置点击时的阴影高度

this.padding, //内边距

this.visualDensity, // 按钮布局的紧凑程度

this.shape, //设置形状

this.clipBehavior = Clip.none,

this.focusNode, //在Flutter使用FocusNode来捕捉监听焦点获取与失去

this.autofocus = false,

this.materialTapTargetSize, //是配置组件点击区域大小的属性,很多组件都有

this.animationDuration, //[shape]和[elevation]的动画更改的持续时间。

this.minWidth, //最小宽度

this.height, //高度

this.enableFeedback = true, // 检测到的手势是否应提供声音和/或触觉反馈。例如,在Android上

// ,点击会产生咔哒声,启用反馈后,长按会产生短暂的振动。通常,组件默认值为true。

this.child, //子view

}) : assert(clipBehavior != null),

3.1 属性

| 编号 | 属性 | 说明 |

| :-: | :-: | :-: |

| 1 | onPressed | 点击事件监听,传 null 表示按钮禁用 |

| 2 | onHighlightCh

上一篇:怎么拍手抓人照片?

下一篇:三通接线宝典,轻松上手,掌握短三通接线技巧!