使用Dart迭代DataSnapshot

时间:2017-02-25 01:59:54

标签: firebase firebase-realtime-database dart

void _newMessage(fb.QueryEvent event) {

    fb.DataSnapshot d = event.snapshot;

    // here want to process each of child of d

}

我想我应该使用d.forEach()。是否有使用Dart迭代DataSnapshot子项的示例?

1 个答案:

答案 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动态语法正确。