I want to show and hide HomeCategory objects based on a bool. I have this in place currently:
_isOn ? HomeCategory(0, Icons.check, Colors.blue[800], "Check In", [Task(0, "Check In", true),]) : "",
However it throws an error because I am passing an empty string if its turned off. How can I pass it an empty object or hide it? It is a list like so:
_isOn ? HomeCategory(0, Icons.check, Colors.blue[800], "Check In", [Task(0, "Check In", true),]) : "",
HomeCategory(1, Icons.chat_bubble, Colors.red, "Forums", [ Task(1, "Questions", true),]),
HomeCategory(2, Icons.star, Colors.blue[200], "Goals", [ Task(2, "Goals", true),]),
HomeCategory(3, Icons.monetization_on, Colors.orange[700], "Budget", [ Task(3, "Budget", true),]),
HomeCategory(4, Icons.shopping_basket, Colors.brown[300], "Shopping", [ Task(4, "Items", true),]),
HomeCategory(5, Icons.calendar_today, Colors.purple[900], "My Day & Calendar", [ Task(4, "Events", false),]),
HomeCategory(6, Icons.check_circle_outline, Colors.teal[700], "Check Out", [ Task(4, "Tasks", false),]),
HomeCategory(7, Icons.dock, Colors.grey[700], "Connect", [ Task(4, "Tasks", false),]),
HomeCategory(8, Icons.local_pharmacy, Colors.green, "My Medication", [ Task(4, "Tasks", false),]),
HomeCategory(9, Icons.settings, Colors.yellow[800], "Settings", [ Task(4, "Tasks", false),]),
Overview. The conditional ternary operator assigns a value to a variable based on some conditions. It is used in place of the if statement. This operator also controls the flow of logical execution in the code. Note: The ternary operator is the only dart operator that takes 3 operators.
An operator that selects between two expressions within an AHDL or Verilog HDL arithmetic expression.
Example: C Ternary Operatorprintf("You can vote") - expression1 that is executed if condition is true. printf("You cannot vote") - expression2 that is executed if condition is false.
The conditional (ternary) operator is the only JavaScript operator that takes three operands: a condition followed by a question mark ( ? ), then an expression to execute if the condition is truthy followed by a colon ( : ), and finally the expression to execute if the condition is falsy.
You can do this :
_isOn ? HomeCategory() : SizedBox()
But since it is in a List<Widget>
, an if
condition is cleaner :
if(_isOn)
HomeCategory()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With