void main() {
int pid = 12;
int data1 = [12][1];
for (int i = 0; i < pid; i++) {
data1[i][0] = 0; // This is wrong
}
}
Error message: The operator ‘[]’ isn’t defined for the type ‘int’.Try defining the operator ‘[]’
// This is not wrong in other languages,Please help answer thank you.
//Why doesn’t this expression work? How to write it correctly
>Solution :
Here is the code with correct syntax.
void main() {
int pid = 12;
List<List<int>> data1 = List.generate(pid, (_) => [0, 0]); // Initialize a 2D list
for (int i = 0; i < pid; i++) {
data1[i][0] = 0; // Assign 0 to the first element of each sublist
}
}