I am programming in Dart and I need a multi-dimensional array to be filled with some data. But when I tried to run it, data at previous indexes were overwritten.
Here is my code:
List<List<String>> list = List.filled(4, List.filled(4, ""));
String toFill = "abcdefghijklmnop";
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
list[i][j] = toFill[i * 4 + j];
}
}
print(list);
I expected output of print() function to be
[[a, b, c, d], [e, f, g, h], [i, j, k, l], [m, n, o, p]]
but when I run it, it printed
[[m, n, o, p], [m, n, o, p], [m, n, o, p], [m, n, o, p]]
I don't know, why the last part is duplicating over to previous values.
I'd be glad for any help.
Thanks