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.
sqljocky dont save the data in list
Pregunta
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();
}
Solución
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow