using valuekeys for keeping track of mounts in query & mutations

QueryBuilder & MutaionBuilder are now null proof
This commit is contained in:
Kingkor Roy Tirtho
2022-06-20 12:28:37 +06:00
parent 7d337e02da
commit d7635abb0e
9 changed files with 134 additions and 56 deletions
+6 -6
View File
@@ -61,7 +61,7 @@ class Query<T extends Object, Outside> extends ChangeNotifier {
/// used for keeping track of query activity. If the are no mounts &
/// the passed cached time is over than the query is removed from
/// storage/cache
Set<Widget> _mounts = {};
Set<ValueKey<String>> _mounts = {};
Query({
required this.queryKey,
@@ -123,20 +123,20 @@ class Query<T extends Object, Outside> extends ChangeNotifier {
// all methods
void mount(Widget widget) {
_mounts.add(widget);
void mount(ValueKey<String> uKey) {
_mounts.add(uKey);
}
void unmount(Widget widget) {
void unmount(ValueKey<String> uKey) {
if (_mounts.length == 1) {
Future.delayed(_cacheTime, () {
_mounts.remove(widget);
_mounts.remove(uKey);
// for letting know QueryBowl that this one's time has come for
// getting crushed
notifyListeners();
});
} else {
_mounts.remove(widget);
_mounts.remove(uKey);
}
}