How to dynamically update a snapshot<list<foo2>> built by a StreamBuilder<list<stream<foo>>>?

59 Views Asked by At

In my Flutter app, I have a StreamBuilder<List< DateTime >> that returns a list of DateTimes, and I need to build a Stream for each DateTime in the list. Then, I have a StreamBuilder<List<Stream< Task>>>, which returns a list of Streams of Task objects, one for each DateTime. Finally, I want to convert this list of Streams into a single List snapshot.

I have tried to use combineLatest to merge the Stream of Task objects, but this only works initially and doesn't update when the list of DateTimes changes. I want to find a way to dynamically update the list of tasks based on the changing list of DateTimes.

I have access to two methods from a custom Firestore database class:

Stream<List> taskStream(DateTime date) Stream userDays(String userId) I want to avoid changing the StreamBuilder key to prevent unwanted rebuilds.

How can I dynamically update the list of tasks based on the changing list of DateTimes? Any help or guidance would be appreciated.

This is the general idea of what i want to do, but the task snapshot doesnt get updated

StreamBuilder<List<DateTime>>(
  stream: dateTimeStream, // stream of list of DateTime objects
  builder: (BuildContext context, AsyncSnapshot<List<DateTime>> dateTimeSnapshot) {
    Stream<List<Task>> taskStream = Rx.combineLatest<DateTime, List<Task>>(
      dateTimeSnapshot.data.map((dateTime) => taskStream(dateTime)),
      (List<Task> tasks) => tasks,
    );
    return StreamBuilder<List<Task>>(
      stream: taskStream, // stream of list of tasks for each DateTime
      builder: (BuildContext context, AsyncSnapshot<List<Task>> taskSnapshot) {
        // build UI using list of tasks in taskSnapshot
      },
    );
  },
);
0

There are 0 best solutions below