skip to Main Content

What i’m trying to achieve is something similar to this

bigArray [

[val1, val2, val3],

[val1, val2, val3],

.

.

.

]

basically each inner array has a fixed length of 4, whereas the outer array (bigArray) contains all the inner arrays.

I know this is possible in Java, but i have not been able to recreate it in Flutter

2

Answers


  1. You can use List<List<T>> without complications, but I think a Map<String,List<T>> will suit you best.

    Login or Signup to reply.
  2. Yes, it is possible to create an array of arrays in Dart and Flutter. You can do this by creating a list of lists, where each element in the list is another list with a fixed length.

    List<List<String>> bigArray = [];
    
    // Initialize the inner lists
    for (int i = 0; i < 5; i++) {
     List<String> innerList = ['val1', 'val2', 'val3'];
     bigArray.add(innerList);
    }
    
    print(bigArray); // Output: [[val1, val2, val3], [val1, val2, val3], [val1, 
                     //val2, val3], [val1, val2, val3], [val1, val2, val3]]
    

    Note that in Dart, you don’t need to specify the type of the inner lists explicitly when declaring bigArray, as the type inference will automatically infer the type based on the initialization. However, if you want to be explicit about the types, you can declare bigArray like this:

    List<List<String>> bigArray = <List<String>>[];
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search