我不确定你的onCursor()
函数正在做什么/调用。我假设您的 values 变量是一个列表。
我自己做了类似的事情,但使用回调而不是未来/完成者。你这里只有一个小函数片段。我将把它冲洗掉一些,希望能添加一些细节:
// Accept the indexeddb Database, and return a future which
// will provide the list of values from 'someKey'
Future<List<String>> getSomeKeyValues(Database db) {
var values = new List<String>();
var completer = new Completer();
var store = db.transaction('DB_STORE', 'readwrite').objectStore('DB_STORE');
store.openCursor(autoAdvance: true).listen((cursor) {
if(cursor != null && cursor.value != null) {
// Note cursor.value is actually a Map<String, String>
// of collection's key and value
values.add(cursor.value['someKey']); // get the value key 'someKey'
}
}, onDone: () => completer.complete(values),
onError: (e) => completer.completeError(e));
return completer.future;
}
然后我们会像这样调用这个函数:
getSomeKeyValues(myDatabase).then((results) {
for(var value in results) {
print(value);
}
}