skip to Main Content

I have a reactive bool. Now if that is true I show a widget , but in case that is false then I don’t need to show anything at all in that place.

As of now I am adding a Empty Container() or SizedBox.shrink() if the bool is false. Is there any way to not adding any Widget at all?

2

Answers


  1. If the widget is child of a parent that as several children, like a Column or Row you can easily insert if statements within the list of children. Like this for example

    Column(children: [
      SomeWidget(),
      SomeOtherWidget(),
      if (myBool) ConditionalWidget(),
      LastWidget(),
    ],)
    
    Login or Signup to reply.
  2. If i not misunderstanding you want to hide it without using condition you can use Visibility to hide your widget but for conditional widget just do like @Ivo Answer

    Visibility(
      visible:  // bool,
      child:  child //widget,
    ),
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search