Dart - Help me understand how this code on Dart works Dart - Help me understand how this code on Dart works dart dart

Dart - Help me understand how this code on Dart works


return new Future<List>(() {  res.toList() // <== 1.) registers a future for later execution // <== 3.) execute `toList()`    .then((List<mysql.Row> rows) {    rows.forEach((mysql.Row row) { // <== 4.) execute rows.forEach      data.add({name: row.name, email: row.email});    });  });  return data; // <== 2.) return data});

3.) is executed after the code calling the above code has finished all sync execution

return new Future<List>(() {  return res.toList() // <== returning the future keeps the async parts connected                      // and one is executed after the other    .then((List<mysql.Row> rows) {      rows.forEach((mysql.Row row) { // <== 4.) execute rows.forEach        data.add({name: row.name, email: row.email});      });    })    .then((_) data);  // <== the same here, return data **after** the previous statements are finished  });});