void _newMessage(fb.QueryEvent event) {
fb.DataSnapshot d = event.snapshot;
// here want to process each of child of d
}
我想我应该使用d.forEach()。是否有使用Dart迭代DataSnapshot子项的示例?
答案 0 :(得分:1)
void addMessage( fb.DataSnapshot d){
PCDChatMessage msg = new PCDChatMessage.fromMap(d.val());
pcdChatMessages.add(msg); //todo don't duplicate messages
}
void _newMessage(fb.QueryEvent event) {
fb.DataSnapshot d = event.snapshot;
// process each child of d
d.forEach((k) => addMessage(k));
}
这对我有用 - 我必须让Dart动态语法正确。