0

我有一个动画列表,构建功能包含在应用程序主体的堆栈中。每当数据库中的某些内容更新时,流构建器就不会重建.. items 由函数在 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]),
            );
          },
        );
      },
    )
    );
  }
4

1 回答 1

0

有错误的initialItemCount,应该是items.length

于 2019-10-09T17:49:11.620 回答