简体   繁体   中英

Flutter - RaisedButton onPressed with Multiple Condition

Just move to flutter and little bit frustration about multiple condition in raisedbutton onpressed.

I have bool buttonDisabled1 and bool buttonDisabled2 . I want if buttonDisabled1 == true AND buttonDisabled2 == true (both of them == true), so onPressed = null , it works.

However, if buttonDisabled1 or buttonDisabled2 == false (ONE of them is false) onPressed not null anymore.

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,
),

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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