title: Initialize list of lists in Dart
body: <p>I have a grid in Dart implemented as follows:</p>
  
  <pre><code>class Cell {
      int row; 
      int col;
      Cell(this.row, this.col);
  }
  
  class Grid {
      List&lt;List&lt;Cell&gt;&gt; rows = new List(GRID_SIZE);
      Grid() {
          rows.fillRange(0, rows.length, new List(GRID_SIZE));
      }
  }
  </code></pre>
  
  <p>And i can't seem to find a way to initialize each cell with the proper <code>row</code> and <code>col</code> values: I tried with two nested for loops, like this</p>
  
  <pre><code>for(int i = 0; i &lt; GRID_SIZE; i++) {
      for(int j = 0; j &lt; GRID_SIZE; j++) {
          rows[i][j] = new Cell(i, j);
      }
  }
  </code></pre>
  
  <p>But due to Dart's closure error protection described <a href="https://www.dartlang.org/resources/dart-tips/dart-tips-ep-8" rel="nofollow noreferrer">here</a>, my grid ends up being populated with cells having <code>GRID_SIZE - 1</code> in the <code>row</code> member.</p>
  
  <p>So, what's the idiomatic way in Dart to initialize a nested list?</p>