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
@@ -34,7 +34,7 @@ class Mutation<T extends Object, V> extends ChangeNotifier {
/// used for keeping track of mutation activity. If the are no mounts &
/// the passed cached time is over than the mutation is removed from
/// storage/cache
Set<Widget> _mounts = {};
Set<ValueKey<String>> _mounts = {};
@protected
final Set<MutationListener<T>> onDataListeners = {};
@@ -87,20 +87,20 @@ class Mutation<T extends Object, V> extends ChangeNotifier {
bool get isInactive => _mounts.isEmpty;
// 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);
}
}