To create a Two-Dimensional List in Dart, you can use nested lists or lists of lists to represent rows and columns.
In this example,
void main() {
List<List<int>> matrix = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
];
matrix.forEach((row) {
print(row);
});
}
[1, 2, 3] [4, 5, 6] [7, 8, 9]
In this example,
void main() {
List<List<String>> matrix = [
['apple', 'banana', 'cherry'],
['orange', 'grape', 'kiwi'],
];
matrix.forEach((row) {
print(row);
});
}
[apple, banana, cherry] [orange, grape, kiwi]
In this tutorial, we learned How to create a Two Dimensional List in Dart language with well detailed examples.