Frage

  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();
  }
War es hilfreich?

Lösung

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.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top