简体   繁体   中英

Flutter: hide/show widget by key dynamically

How can we show/hide widget inside another widget in flutter?

I have list of question which are inside list view builder I want to hide questions on user answer selection.

if you have all equations in question[] and whether to show them in show[], you could place into listbuild

return (bool[index] ? Card(child:Text(question[index])) : Container())

This returns the card in bool is true and the empty (not displayed container) otherwise.

(I think the other answer would do the trick too)

Another option you can consider though is using the Visibility widget to wrap the "question" widget and toggle the visible property based on a bool. To make this (or the above solution) work, you'd want to update the value of this bool using eg setState on the method called when,as you say, "user answer selection" happens.

Of course, if you have a more complicated application it might make more sense to use Provider for state management and wrap all of this in a Consumer.

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