I assume you want to do something like this (note the unverified code):
Future<DBObject> load(DBObject object, String id) { var query = "select ... where id='$id'"; // Note: check for SQL injection. return pool.query(query) .then((result) => result.toList()) .then((list) => list.forEach((row) => object.import(row))) .then((_) => object); }
Have you read this article about using Futures?
The key point is that the method is asynchronous, and the calling code needs to wait for it to finish, then it should return a Future object (or a stream in some cases). There is no way in Dart to get the "block" function to wait for an asynchronous result. Feel free to ask some more questions in the comments.
Greg lowe
source share