skip to Main Content

I’m using the widget Wrap this way:

Wrap(
  crossAxisAlignment: WrapCrossAlignment.center,
  spacing: 5,
  children: [
    condition1 ? Container(width: 50, height: 50, color: Colors.blue) : SizedBox(),
    condition2 ? Container(width: 50, height: 50, color: Colors.red) : SizedBox(),
    condition3 ? Container(width: 50, height: 50, color: Colors.green) : SizedBox()
  ]
)

How can I apply the spacing only on the Container and not on the SizedBox ?

2

Answers


  1. Try to wrap Padding on Container widget

    Login or Signup to reply.
  2. If SizedBox is only there as a placeholder and is not useful in any other way, you don’t need it at all. Check out alternative syntax:

    Wrap(
            crossAxisAlignment: WrapCrossAlignment.center,
            spacing: 5,
            children: [
              if (condition1) Container(width: 50, height: 50, color: Colors.blue),
              if (condition2) Container(width: 50, height: 50, color: Colors.red),
              if (condition3) Container(width: 50, height: 50, color: Colors.green),
            ])
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search