helloitsme3
helloitsme3

Reputation: 307

How to create list of n variables?

Number of variables changes depending on game level.

I want to create list of variables in loop, for example if i = 4 I need variables: size1, size2, size3, size4. Creating names is also problematic for me, like how to create sizen variables?

Thank you in advance

Upvotes: 0

Views: 130

Answers (1)

BLKKKBVSIK
BLKKKBVSIK

Reputation: 3548

You can probably use the constructor List.generate.

Here's an example on how to generate a list of 100 int:

final myList = List.generate(100, (index) => index);

print(myList) // [0, 1, 2, 3, 4, 5, ... 99, 100]

Upvotes: 1

Related Questions