Description
I have the following object structure, making use of the firestore nested collections:
class A {
final String name;
final List<B> bs;
final String createdBy;
}
To retrieve data i wrote a stream:
Stream<List<A>> get allA{
return aCollection.snapshots().asyncMap((snapshot) async {
return Future.wait(snapshot.docs.map((doc) async {
final bSnapshots=
await bCollection(doc.reference).get();
final bs =
bSnapshots.docs.map((doc) => doc.data()).toList();
final a = A(
name: doc.data().name,
bs: bs,
createdBy: doc.data().createdBy,
);
return a;
}).toList());
});
}
I display all data in a ListView, wich gets it from a StreamProvider:
return StreamProvider<List<A>>.value(
lazy: false,
value: DatabaseService().allA,
initialData: [],
child: ...
In the child widget:
final as = Provider.of<List<A>>(context);
Problem
When i make a change in the sub collection “bs” the StreamProvider for List is not triggered, and so it doesn’t reload the ListView. Is there any posibility to notify or hard reload the StreamProvider?
I already tried to adapt the hashcode of class A:
@override
bool operator ==(Object other) {
return other is A &&
other.name == name &&
ListEquality().equals(other.bs, bs) &&
other.createdBy == createdBy;
}
@override
int get hashCode =>
name.hashCode ^ ListEquality().hash(bs) ^ createdBy.hashCode;
That sounded promising to me, but it didnt work.
Philipp is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.