0
  import 'package:sqljocky/sqljocky.dart';

  void recopilaDatos(){

    List <String> listaCorreos = new List(); 
    var pool = new ConnectionPool(host: 'localhost', port: 3306, user: 'root', password: 'root', db: 'prueba', max: 5);
    // Realizar una query.
    pool.query('select * from usuarios').then( (result) {
      result.forEach(      
        (row)   {listaCorreos.add("user: ${row[0]}"); /*don't work*/}   
      );

    });
    //listaCorreos.add("manolo"); //OK
    print (listaCorreos.length);
    for (var nombre in listaCorreos){
      print(nombre);
    }
  }

  void main() {
    recopilaDatos();
  }
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
Juan Antonio
  • 2,451
  • 3
  • 24
  • 34
  • Have you tried some debugging or print out the result you get. I guess you don't get anything back from the database. – Günter Zöchbauer Feb 02 '14 at 21:03
  • if i change "listaCorreos.add(...)" for "print(...)", in the console the values appear. I don't understend Why it does not work the code, if i write "listaCorreos.add(..)" in other place work. – Juan Antonio Feb 02 '14 at 23:16

1 Answers1

0

You printing the list before its populated, this is why the manolo entry works and the print in the then clause works also, you can only be sure the list is set up in your then clause, not outside of it.

user2685314
  • 1,059
  • 6
  • 9