How to count the switches that are toggled on or off in flutter?

Viewed 30

For a simple flutter app which displays 3 types of photos (turtles, butterflies and birds) I have for each type one corresponding switch which either shows or hides all pictures in the category.

How can I display how many categories are shown? eg, the butterfly switch is off, but the turtles and birds switches are on, thus displaying only turtle and bird pictures.

Can I make a bool for each switch like swicth1On = true, etc... and count the amount of switches that are on, or is there a better solution?

The resulting string should be: Text('${categoryCount} of ${amount of item-types} categories'), -> it also has to either show category or categories when one or more switches are toggled on. -> categoryCount is then the amount of item-type-switches that are on.

Thx

0 Answers
Related