Firestore更改时,Streambuilder不会更新

时间:2019-10-01 10:27:48

标签: flutter stream-builder

我有一个动画列表,构建功能包含在应用程序主体的堆栈中。 每当数据库中的内容更新时,streambuilder都不会重建。 项是通过函数在init中设置的:

  Stream<List<Task>> getTasks(){
    try {
      Firestore.instance
          .collection("lists")
          .document(tasklist.postID)
          .collection("tasks")
          .snapshots();
    }
    on Exception {
      error();
    }
    return ref.snapshots().map((list) =>
        list.documents.map((doc) => Task.fromFireStore(doc)).toList());
}
  Widget _buildTasksList() {
    return new Expanded(
      child: new StreamBuilder(
      stream: items,
      builder: (BuildContext context, AsyncSnapshot snapshot) {
        if (!snapshot.hasData) {
          return new Text("Loading");
        }
        return new AnimatedList(
          initialItemCount: tasks.length,
          key: _listKey,
          itemBuilder: (context, index, animation) {
            print(index);
            return new TaskRow(
              task: listModel[index],
              animation: animation,
              listModel: listModel,
              tasklist: tasklist,
              onChange: () => _onChange(listModel[index]),
            );
          },
        );
      },
    )
    );
  }

1 个答案:

答案 0 :(得分:0)

具有错误的initialItemCount,应为items.length