@@ -44,12 +44,6 @@ class InheritedContextRefElement extends InheritedElement {
44
44
refs.add (ref);
45
45
}
46
46
47
- /// This is used to keep track of the dependent [Element] s that have been
48
- /// deactivated in the current frame. We need to keep track of them to
49
- /// not dispose of the [ValueProvider] s too early, while the [Element] can
50
- /// still be reactivated in the same frame.
51
- final _deactivatedElements = HashSet <Element >.identity ();
52
-
53
47
ValueProvider <T > bind <T >({
54
48
required BuildContext context,
55
49
required Ref <T > ref,
@@ -59,11 +53,6 @@ class InheritedContextRefElement extends InheritedElement {
59
53
}) {
60
54
assert (context is Element );
61
55
62
- // If bind is called, it means the element is active. If it was
63
- // previously deactivated - remove it from the list of deactivated
64
- // elements. This is important to handle the element re-parenting.
65
- _deactivatedElements.remove (context);
66
-
67
56
// Make [context] dependent on this element so that we can get notified
68
57
// when the [context] is removed from the tree.
69
58
context.dependOnInheritedElement (this );
@@ -139,11 +128,9 @@ class InheritedContextRefElement extends InheritedElement {
139
128
// yet unmounted. The element can be reactivated during the same fame.
140
129
// So, let's not dispose the context data immediately, but rather wait
141
130
// until the end of the frame to see if the element is reactivated.
142
- _deactivatedElements.add (dependent);
143
131
SchedulerBinding .instance.addPostFrameCallback ((_) {
144
- if (_deactivatedElements. contains ( dependent) ) {
132
+ if (! dependent.mounted ) {
145
133
_disposeContextData (dependent);
146
- _deactivatedElements.remove (dependent);
147
134
}
148
135
});
149
136
super .removeDependent (dependent);
@@ -163,7 +150,6 @@ class InheritedContextRefElement extends InheritedElement {
163
150
164
151
@override
165
152
void unmount () {
166
- _deactivatedElements.clear ();
167
153
for (final element in _refs.keys.toList (growable: false )) {
168
154
_disposeContextData (element);
169
155
}
0 commit comments