Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to repeat value of array in Flutter

I'm iOS Developer and new for Flutter. In the Swift language If we want to repeat the same value for a specific time in the Array.

Ex.

If In the Array I want to repeat 0 for 5 times then I can do by one line of code like below.

let fiveZeros = Array(repeating: "0", count: 5)
print(fiveZeros)
// Prints "["0", "0", "0", "0", "0"]"

init(repeating:count:) function used.

So I'm looking for any function or code that works in Flutter.

I do googling but didn't find a solution.

like image 792
Govaadiyo Avatar asked May 30 '18 06:05

Govaadiyo


1 Answers

In dart you can use the filled factory of List.

final list = List.filled(5, 0);
print(list);  //-> [0, 0, 0, 0, 0]

See more in the list docs.

like image 124
Edman Avatar answered Nov 14 '22 03:11

Edman