我们挨个说明属性的作用及用法:
onPressed 用户点击此按钮时的回调函数。
RaisedButton(
onPressed: () {
//点击事件处理
}
)
onLongPress 和上面一样的,用户长按此按钮时的回调函数。
RaisedButton(
onLongPress: () {
//长按事件处理
}
)
onHighlightChanged 水波纹高亮变化回调
RaisedButton(
onHighlightChanged: (bool) {
debugPrint(bool.toString());//有水波纹时返回true,水波纹消失(放开按钮)返回false
}
)
textTheme 按钮的样式(文字颜色、按钮的最小大小,内边距以及shape)
RaisedButton(
textTheme: ButtonTextTheme.accent,//改变了文字颜色和点击背景色
)
textColor 文本颜色
RaisedButton(
textColor: Color(0xFFFFFF),
)
disabledTextColor 禁用状态下的文本颜色
color 背景颜色
disabledColor 禁用状态下的背景颜色
focusColor 获取焦点之后的背景色吧,没有测试出来
hoverColor 鼠标悬停在按钮上的时候的背景色
highlightColor 水波纹颜色
splashColor 扩散水波纹的颜色
colorBrightness 背景亮度(dark/light)
elevation 阴影深度
focusElevation 聚焦时阴影深度
hoverElevation 鼠标悬停时阴影深度
highlightElevation 水波纹变化时阴影深度
disabledElevation 禁用时阴影深度
padding 内边距
shape 形状,需要使用ShapeBorder的子类,如
shape: RoundedRectangleBorder (
borderRadius: BorderRadius.all(Radius.circular(50))
)
设置圆角
clipBehavior 裁剪(none/hardEdge/antiAlias/antiAliasWithSaveLayer),默认是none,不裁剪
focusNode 监听及控制焦点,详情看https://developer.aliyun.com/article/763095
autofocus 是否自动获取焦点,默认false
materialTapTargetSize 是配置组件点击区域大小的属性,有2个值,分别为:
- padded:最小点击区域为48*48。
- shrinkWrap:子组件的实际大小。
animationDuration 时长,具体是什么的时长,没试出来
child 子控件,一般用来显示文字,如下
RaisedButton(
child: Text('继续拍照'),
)
可以给背景加个渐变色效果
RaisedButton(
child: Container(
decoration: const BoxDecoration(
gradient: LinearGradient(
colors: <Color>[
Color(0xFF0D47A1),
Color(0xFF1976D2),
Color(0xFF42A5F5),
],
),
),
padding: const EdgeInsets.all(10.0),
child: const Text('Gradient Button',
style: TextStyle(fontSize: 20)),
),
)