当前位置:网站首页>Flutter RaisedButton怎样禁用
Flutter RaisedButton怎样禁用
2022-07-13 18:10:00 【一叶飘舟】
在开发中,我们有时候需要RaisedButton组件禁用,满足条件后可以点击。
const RaisedButton({
Key key,
@required VoidCallback onPressed,
VoidCallback onLongPress,
ValueChanged<bool> onHighlightChanged,
MouseCursor mouseCursor,
ButtonTextTheme textTheme,
Color textColor,
Color disabledTextColor,
Color color,
Color disabledColor,
Color focusColor,
Color hoverColor,
Color highlightColor,
Color splashColor,
Brightness colorBrightness,
double elevation,
double focusElevation,
double hoverElevation,
double highlightElevation,
double disabledElevation,
EdgeInsetsGeometry padding,
VisualDensity visualDensity,
ShapeBorder shape,
Clip clipBehavior = Clip.none,
FocusNode focusNode,
bool autofocus = false,
MaterialTapTargetSize materialTapTargetSize,
Duration animationDuration,
Widget child,
}) 下面我们来看看常用属性

我们看下disabledColor属性源码中的描述:
/// The fill color of the button when the button is disabled.
///
/// The default value of this color is the theme's disabled color,
/// [ThemeData.disabledColor].
///
/// See also:
///
/// * [color] - the fill color of the button when the button is [enabled].
final Color disabledColor;
/// Whether the button is enabled or disabled.
///
/// Buttons are disabled by default. To enable a button, set its [onPressed]
/// or [onLongPress] properties to a non-null value.
bool get enabled => onPressed != null || onLongPress != null;按钮是否enable就看onPressed或者onLongPress是不是为空,不为空就可点击,为空则不能点击。
那么,如果想禁用按钮使按钮变色的话,只需在点击事件处理即可,例如:
RaisedButton(
disabledColor: Res.COLOR.text_999999,
color: Res.COLOR.title_bg,
padding: EdgeInsets.only(top: 16, bottom: 16),
child: const Text('提交',style: TextStyle(color: Colors.white)),
onPressed: _submit(),
)
void Function() _submit() {
return selectedContactList.isNotEmpty ? () => onBtnPressed() : null;
}
void onBtnPressed() {
var params = <String, dynamic>{
'select_data': '123'
};
FlutterBoost.singleton.closeCurrent(result: params);
}边栏推荐
- vscode更新时,报错 Failed to install visual Studio Code update. Updates may fail due to anti-virus softwa
- Master-slave copy reading and writing separation nanny level teaching
- Rust Thrift Demo
- Day 13 of leetcode + day 3 of DL
- Thresh - the dynamic scheme of fluent based on JS
- jsonp原理
- 解决nodejs中mysql查询数据中bigint类型数据精度缺失问题
- 百度上传webuploader
- neo4j学习资料整理
- prism导航功能
猜你喜欢
随机推荐
Day 14 of leetcode
TFIDF sklearn code call
Recursive implementation of exponential enumeration
TestCafe之定位、操作页面元素以及验证执行结果
When vscode is updated, the error failed to install visual studio code update Updates may fail due to anti-virus softwa
Concurrent simulation of program ape's exclusive "pressure test tool"
Thoroughly understand how Kube scheduler completes scheduling
nacos安装教程
认识kubenetes的核心组件之一kubelet
C#使用TcpListener进行聊天通信
tensorflow errors_impl.InvalidArgumentError
rasa会话数据存储 RedisTrackerStore 连接哨兵
Day 4 of leetcode question brushing
微信小程序开发—(五)弹出框
Day 7 of DL
Day 6 of leetcode question brushing
分词工具汇总
如何选择接口自动化测试工具
aws上创建eks集群
nodejs使用multe实现文件上传,并将文件存储在服务器









