I have a List<String> and I want to create a square matrix (2-dimensional array/list) of Set<String> with the same dimensions as the length of the List<String>.
I tried using
List.filled(entries.length, List.filled(entries.length, Set<String>()));
but the problem is that it seems that each row of my matrix refers to the same list instance, so changing a value in one row changes it in all the others as well.
So then I tried
List.filled(entries.length, List.from(List.filled(entries.length, Set<String>())));
but I still have the same problem. Eventually I surrendered and resorted to
List<List<Set<String>>> matrix = [];
for(int i=0; i<entries.length; i++) {
List<Set<String>> row = [];
for (int n = 0; n<entries.length; n++) {
row.add(Set<String>());
}
matrix.add(row);
}
It works, but it's ugly. Is there a cleaner way to do this?