0

I've been playing around in Flutter for the last couple of weeks and I'm finding that the documentation is useless.

I'm trying find documentation on how to setup a 2D Array. Something that should be easy to find, but I can't find anything useful on how to format an array. After much Google searching, I was able to create a 1D array, but haven't had any luck on creating a 2D Array.

Here's my 1D Array example in case someone comes across this post for that reason (the keyword 'static' shouldn't be required, it just allows me to use the Array on different scripts in my project.):

static var vGrades = ['PreK', 'K', '1st', '2nd', '3rd', '4th', '5th', '6th', '7th', '8th', '9th', '10th', '11th', '12th'];

Note, I don't want to name each column, just want to reference an Array like "vArray[2][3]" (3rd indexed line, 4th indexed element).

2 Answers 2

1

Follow This

int row = 3;
int col = 4;
var todo_list = List.generate(row, (i) => List(col), growable: false);
 //For fill;
twoDList[0][1] = "element";
print(twoDList);
 // [[null, element, null, null], [null, null, null, null], [null, null, null, null]]
Sign up to request clarification or add additional context in comments.

Comments

0

for 2d String List like MyList[10][2]:

var MyList   =List.generate(10, (i) => List.filled(2, "", growable: false), growable: true);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.