Flutter RaisedButton怎样禁用
Posted 一叶飘舟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flutter RaisedButton怎样禁用相关的知识,希望对你有一定的参考价值。
在开发中,我们有时候需要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);
以上是关于Flutter RaisedButton怎样禁用的主要内容,如果未能解决你的问题,请参考以下文章
Flutter-如何以编程方式触发RaisedButton?
Flutter - 如何在点击时切换 RaisedButton 的颜色?
Flutter for web - RaisedButton 周围的 GestureDetector