2

I want to add widget attribute only if condition is met - I want the 'left' attribute to appear only if the index i is bigger than 0. How can I do this?

 for(int i = 0; i < attendingImagesList.length; i++) {
          avatars.add(
            Positioned(
              left: ((avatarWidth - overlayWidth)*i).toDouble(),
              child:  CircleAvatar(
                radius: 14,
                backgroundImage: NetworkImage(this.attendingImagesList[i])
              )
          ));
        }

1 Answer 1

4

Create a ternary and if it's zero make it null.

for(int i = 0; i < attendingImagesList.length; i++) {
          avatars.add(
            Positioned(
              left: i == 0 ? null : ((avatarWidth - overlayWidth)*i).toDouble(),
              child:  CircleAvatar(
                radius: 14,
                backgroundImage: NetworkImage(this.attendingImagesList[i])
              )
          ));
        }
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.