문제

  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();
  }
도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top