简体   繁体   English

Flutter - RaisedButton onPressed 有多个条件

[英]Flutter - RaisedButton onPressed with Multiple Condition

Just move to flutter and little bit frustration about multiple condition in raisedbutton onpressed.只需移动到 flutter 并且对按下的凸起按钮中的多个条件有点沮丧。

I have bool buttonDisabled1 and bool buttonDisabled2 .我有 bool buttonDisabled1和 bool buttonDisabled2 I want if buttonDisabled1 == true AND buttonDisabled2 == true (both of them == true), so onPressed = null , it works.我想要if buttonDisabled1 == true AND buttonDisabled2 == true (两者都 == true),所以onPressed = null ,它可以工作。

However, if buttonDisabled1 or buttonDisabled2 == false (ONE of them is false) onPressed not null anymore.但是,如果buttonDisabled1 or buttonDisabled2 == false (其中一个为 false) onPressed不再是 null。

My goal is:我的目标是:

buttonDisabled1 == true AND buttonDisabled2 == true -> onpressed null;
buttonDisabled1 == false AND buttonDisabled2 == true -> onpressed null; 
buttonDisabled1 == true AND buttonDisabled2 == false -> onpressed null; 
buttonDisabled1 == false AND buttonDisabled2 == false -> onpressed not null;

Thanks in advice:)多谢指教:)

Below my code, none of them works.在我的代码下面,它们都不起作用。

Widget build(BuildContext context) {
  bool buttonDisabled1 = true;
  bool buttonDisabled2 = true;

RaisedButton(
  child: Text('Click'),
  onPressed: buttonDisabled1 && buttonDisabled2 ? null : (){},
),
}
RaisedButton(
  child: Text('Click'),
  onPressed: (buttonDisabled1 && buttonDisabled2) ? null : (){},
),
RaisedButton(
  child: Text('Click'),
  onPressed: ((buttonDisabled1) && (buttonDisabled2)) ? null : (){},
),
RaisedButton(
  child: Text('Click'),
  onPressed: !buttonDisabled1 && !buttonDisabled2 ? (){} : null,
),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM