mirror of
https://github.com/flutter/flutter
synced 2024-10-14 04:02:56 +00:00
Remove remaining uses of childToSlot
(#64273)
The remaining uses of this pattern were all due to wanting to have the child's slot when `Element.forgetChild()` was called. However, when that method is called, the child's `slot` value is still valid in the context of the parent, so the uses can just use `child.slot`. This is the final round of cleanup from the fallout of #63269
This commit is contained in:
parent
90908b0beb
commit
dae720bef4
|
@ -748,7 +748,6 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
|
|||
|
||||
List<Element> _children;
|
||||
final Map<_CupertinoTextSelectionToolbarItemsSlot, Element> slotToChild = <_CupertinoTextSelectionToolbarItemsSlot, Element>{};
|
||||
final Map<Element, _CupertinoTextSelectionToolbarItemsSlot> childToSlot = <Element, _CupertinoTextSelectionToolbarItemsSlot>{};
|
||||
|
||||
// We keep a set of forgotten children to avoid O(n^2) work walking _children
|
||||
// repeatedly to remove children.
|
||||
|
@ -829,12 +828,11 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
|
|||
|
||||
@override
|
||||
void forgetChild(Element child) {
|
||||
assert(slotToChild.values.contains(child) || _children.contains(child));
|
||||
assert(slotToChild.containsValue(child) || _children.contains(child));
|
||||
assert(!_forgottenChildren.contains(child));
|
||||
// Handle forgetting a child in children or in a slot.
|
||||
if (childToSlot.containsKey(child)) {
|
||||
final _CupertinoTextSelectionToolbarItemsSlot slot = childToSlot[child];
|
||||
childToSlot.remove(child);
|
||||
if (slotToChild.containsKey(child.slot)) {
|
||||
final _CupertinoTextSelectionToolbarItemsSlot slot = child.slot as _CupertinoTextSelectionToolbarItemsSlot;
|
||||
slotToChild.remove(slot);
|
||||
} else {
|
||||
_forgottenChildren.add(child);
|
||||
|
@ -848,11 +846,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
|
|||
final Element newChild = updateChild(oldChild, widget, slot);
|
||||
if (oldChild != null) {
|
||||
slotToChild.remove(slot);
|
||||
childToSlot.remove(oldChild);
|
||||
}
|
||||
if (newChild != null) {
|
||||
slotToChild[slot] = newChild;
|
||||
childToSlot[newChild] = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -877,12 +873,11 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
|
|||
@override
|
||||
void debugVisitOnstageChildren(ElementVisitor visitor) {
|
||||
// Visit slot children.
|
||||
childToSlot.forEach((Element child, _) {
|
||||
if (!_shouldPaint(child) || _forgottenChildren.contains(child)) {
|
||||
return;
|
||||
for (final Element child in slotToChild.values) {
|
||||
if (_shouldPaint(child) && !_forgottenChildren.contains(child)) {
|
||||
visitor(child);
|
||||
}
|
||||
visitor(child);
|
||||
});
|
||||
}
|
||||
// Visit list children.
|
||||
_children
|
||||
.where((Element child) => !_forgottenChildren.contains(child) && _shouldPaint(child))
|
||||
|
|
|
@ -2067,7 +2067,6 @@ class _RenderChipElement extends RenderObjectElement {
|
|||
_RenderChipElement(_ChipRenderWidget chip) : super(chip);
|
||||
|
||||
final Map<_ChipSlot, Element> slotToChild = <_ChipSlot, Element>{};
|
||||
final Map<Element, _ChipSlot> childToSlot = <Element, _ChipSlot>{};
|
||||
|
||||
@override
|
||||
_ChipRenderWidget get widget => super.widget as _ChipRenderWidget;
|
||||
|
@ -2082,11 +2081,10 @@ class _RenderChipElement extends RenderObjectElement {
|
|||
|
||||
@override
|
||||
void forgetChild(Element child) {
|
||||
assert(slotToChild.values.contains(child));
|
||||
assert(childToSlot.keys.contains(child));
|
||||
final _ChipSlot slot = childToSlot[child];
|
||||
childToSlot.remove(child);
|
||||
slotToChild.remove(slot);
|
||||
assert(slotToChild.containsValue(child));
|
||||
assert(child.slot is _ChipSlot);
|
||||
assert(slotToChild.containsKey(child.slot));
|
||||
slotToChild.remove(child.slot);
|
||||
super.forgetChild(child);
|
||||
}
|
||||
|
||||
|
@ -2095,11 +2093,9 @@ class _RenderChipElement extends RenderObjectElement {
|
|||
final Element newChild = updateChild(oldChild, widget, slot);
|
||||
if (oldChild != null) {
|
||||
slotToChild.remove(slot);
|
||||
childToSlot.remove(oldChild);
|
||||
}
|
||||
if (newChild != null) {
|
||||
slotToChild[slot] = newChild;
|
||||
childToSlot[newChild] = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2115,12 +2111,10 @@ class _RenderChipElement extends RenderObjectElement {
|
|||
final Element oldChild = slotToChild[slot];
|
||||
final Element newChild = updateChild(oldChild, widget, slot);
|
||||
if (oldChild != null) {
|
||||
childToSlot.remove(oldChild);
|
||||
slotToChild.remove(slot);
|
||||
}
|
||||
if (newChild != null) {
|
||||
slotToChild[slot] = newChild;
|
||||
childToSlot[newChild] = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1526,11 +1526,10 @@ class _RenderDecoration extends RenderBox {
|
|||
}
|
||||
}
|
||||
|
||||
class _RenderDecorationElement extends RenderObjectElement {
|
||||
_RenderDecorationElement(_Decorator widget) : super(widget);
|
||||
class _DecorationElement extends RenderObjectElement {
|
||||
_DecorationElement(_Decorator widget) : super(widget);
|
||||
|
||||
final Map<_DecorationSlot, Element> slotToChild = <_DecorationSlot, Element>{};
|
||||
final Map<Element, _DecorationSlot> childToSlot = <Element, _DecorationSlot>{};
|
||||
|
||||
@override
|
||||
_Decorator get widget => super.widget as _Decorator;
|
||||
|
@ -1545,11 +1544,10 @@ class _RenderDecorationElement extends RenderObjectElement {
|
|||
|
||||
@override
|
||||
void forgetChild(Element child) {
|
||||
assert(slotToChild.values.contains(child));
|
||||
assert(childToSlot.keys.contains(child));
|
||||
final _DecorationSlot slot = childToSlot[child];
|
||||
childToSlot.remove(child);
|
||||
slotToChild.remove(slot);
|
||||
assert(slotToChild.containsValue(child));
|
||||
assert(child.slot is _DecorationSlot);
|
||||
assert(slotToChild.containsKey(child.slot));
|
||||
slotToChild.remove(child.slot);
|
||||
super.forgetChild(child);
|
||||
}
|
||||
|
||||
|
@ -1558,11 +1556,9 @@ class _RenderDecorationElement extends RenderObjectElement {
|
|||
final Element newChild = updateChild(oldChild, widget, slot);
|
||||
if (oldChild != null) {
|
||||
slotToChild.remove(slot);
|
||||
childToSlot.remove(oldChild);
|
||||
}
|
||||
if (newChild != null) {
|
||||
slotToChild[slot] = newChild;
|
||||
childToSlot[newChild] = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1586,12 +1582,10 @@ class _RenderDecorationElement extends RenderObjectElement {
|
|||
final Element oldChild = slotToChild[slot];
|
||||
final Element newChild = updateChild(oldChild, widget, slot);
|
||||
if (oldChild != null) {
|
||||
childToSlot.remove(oldChild);
|
||||
slotToChild.remove(slot);
|
||||
}
|
||||
if (newChild != null) {
|
||||
slotToChild[slot] = newChild;
|
||||
childToSlot[newChild] = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1694,7 +1688,7 @@ class _Decorator extends RenderObjectWidget {
|
|||
final bool expands;
|
||||
|
||||
@override
|
||||
_RenderDecorationElement createElement() => _RenderDecorationElement(this);
|
||||
_DecorationElement createElement() => _DecorationElement(this);
|
||||
|
||||
@override
|
||||
_RenderDecoration createRenderObject(BuildContext context) {
|
||||
|
|
|
@ -1164,7 +1164,6 @@ class _ListTileElement extends RenderObjectElement {
|
|||
_ListTileElement(_ListTile widget) : super(widget);
|
||||
|
||||
final Map<_ListTileSlot, Element> slotToChild = <_ListTileSlot, Element>{};
|
||||
final Map<Element, _ListTileSlot> childToSlot = <Element, _ListTileSlot>{};
|
||||
|
||||
@override
|
||||
_ListTile get widget => super.widget as _ListTile;
|
||||
|
@ -1179,11 +1178,10 @@ class _ListTileElement extends RenderObjectElement {
|
|||
|
||||
@override
|
||||
void forgetChild(Element child) {
|
||||
assert(slotToChild.values.contains(child));
|
||||
assert(childToSlot.keys.contains(child));
|
||||
final _ListTileSlot slot = childToSlot[child];
|
||||
childToSlot.remove(child);
|
||||
slotToChild.remove(slot);
|
||||
assert(slotToChild.containsValue(child));
|
||||
assert(child.slot is _ListTileSlot);
|
||||
assert(slotToChild.containsKey(child.slot));
|
||||
slotToChild.remove(child.slot);
|
||||
super.forgetChild(child);
|
||||
}
|
||||
|
||||
|
@ -1192,11 +1190,9 @@ class _ListTileElement extends RenderObjectElement {
|
|||
final Element newChild = updateChild(oldChild, widget, slot);
|
||||
if (oldChild != null) {
|
||||
slotToChild.remove(slot);
|
||||
childToSlot.remove(oldChild);
|
||||
}
|
||||
if (newChild != null) {
|
||||
slotToChild[slot] = newChild;
|
||||
childToSlot[newChild] = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1213,12 +1209,10 @@ class _ListTileElement extends RenderObjectElement {
|
|||
final Element oldChild = slotToChild[slot];
|
||||
final Element newChild = updateChild(oldChild, widget, slot);
|
||||
if (oldChild != null) {
|
||||
childToSlot.remove(oldChild);
|
||||
slotToChild.remove(slot);
|
||||
}
|
||||
if (newChild != null) {
|
||||
slotToChild[slot] = newChild;
|
||||
childToSlot[newChild] = slot;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3561,8 +3561,10 @@ abstract class Element extends DiagnosticableTree implements BuildContext {
|
|||
/// This updates the child model such that, e.g., [visitChildren] does not
|
||||
/// walk that child anymore.
|
||||
///
|
||||
/// The element will still have a valid parent when this is called. After this
|
||||
/// is called, [deactivateChild] is called to sever the link to this object.
|
||||
/// The element will still have a valid parent when this is called, and the
|
||||
/// child's [Element.slot] value will be valid in the context of that parent.
|
||||
/// After this is called, [deactivateChild] is called to sever the link to
|
||||
/// this object.
|
||||
///
|
||||
/// The [update] is responsible for updating or creating the new child that
|
||||
/// will replace this [child].
|
||||
|
|
Loading…
Reference in a new issue