0

I am looping Text Field hundreds times

for (var i = 0; i < 100; i++)

my label Text is look like this labelText: '${i + 1}',

I want to set Condition if i is below 10 then add extra 0 before number

I did try with like this

'${i < 10 ? "0"i + 1 : i + 1}',

getting error Expected to Find '}'

3
  • 2
    for (var i = 0; i < 100; i++) print(i.toString().padLeft(2, '0')); or in your case: labelText: i.toString().padLeft(2, '0') Commented Sep 1, 2021 at 8:27
  • need to increase by 1 Commented Sep 1, 2021 at 8:32
  • 1
    @JahidulIslam yes, need to increase by 1: labelText: (i + 1).toString().padLeft(2, '0') Commented Sep 1, 2021 at 8:47

2 Answers 2

1

Here is a another solution by using String's padLeft method.

enter image description here

  for (var i = 0 ; i < 100 ; i++) {
    print(i.toString().padLeft(2, '0'));
  }
Sign up to request clarification or add additional context in comments.

1 Comment

Oops, there is a same solution by pskink.
0
for (var i = 0; i < 100; i++){
    print('${i+1 < 10 ? "0${i + 1}" : i + 1}');
  }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.