Unverified Commit 2d0634eb authored by Todd Volkert's avatar Todd Volkert Committed by GitHub

Remove `childToSlot` pattern (#64217)

parent 0fa1de3c
......@@ -779,8 +779,7 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
if (slot is _CupertinoTextSelectionToolbarItemsSlot) {
assert(child is RenderBox);
_updateRenderObject(child as RenderBox, slot);
assert(renderObject.childToSlot.containsKey(child));
assert(renderObject.slotToChild.containsKey(slot));
assert(renderObject.slottedChildren.containsKey(slot));
return;
}
if (slot is IndexedSlot) {
......@@ -807,11 +806,9 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement {
// Check if the child is in a slot.
if (slot is _CupertinoTextSelectionToolbarItemsSlot) {
assert(child is RenderBox);
assert(renderObject.slotToChild.containsKey(slot));
assert(renderObject.childToSlot.containsKey(child));
assert(renderObject.slottedChildren.containsKey(slot));
_updateRenderObject(null, slot);
assert(!renderObject.childToSlot.containsKey(child));
assert(!renderObject.slotToChild.containsKey(slot));
assert(!renderObject.slottedChildren.containsKey(slot));
return;
}
......@@ -919,23 +916,24 @@ class _CupertinoTextSelectionToolbarItemsRenderBox extends RenderBox with Contai
_page = page,
super();
final Map<_CupertinoTextSelectionToolbarItemsSlot, RenderBox> slotToChild = <_CupertinoTextSelectionToolbarItemsSlot, RenderBox>{};
final Map<RenderBox, _CupertinoTextSelectionToolbarItemsSlot> childToSlot = <RenderBox, _CupertinoTextSelectionToolbarItemsSlot>{};
final Map<_CupertinoTextSelectionToolbarItemsSlot, RenderBox> slottedChildren = <_CupertinoTextSelectionToolbarItemsSlot, RenderBox>{};
RenderBox _updateChild(RenderBox oldChild, RenderBox newChild, _CupertinoTextSelectionToolbarItemsSlot slot) {
if (oldChild != null) {
dropChild(oldChild);
childToSlot.remove(oldChild);
slotToChild.remove(slot);
slottedChildren.remove(slot);
}
if (newChild != null) {
childToSlot[newChild] = slot;
slotToChild[slot] = newChild;
slottedChildren[slot] = newChild;
adoptChild(newChild);
}
return newChild;
}
bool _isSlottedChild(RenderBox child) {
return child == _backButton || child == _nextButton || child == _nextButtonDisabled;
}
int _page;
int get page => _page;
set page(int value) {
......@@ -1001,7 +999,7 @@ class _CupertinoTextSelectionToolbarItemsRenderBox extends RenderBox with Contai
childParentData.shouldPaint = false;
// Skip slotted children and children on pages after the visible page.
if (childToSlot.containsKey(child) || currentPage > _page) {
if (_isSlottedChild(child) || currentPage > _page) {
return;
}
......@@ -1165,9 +1163,9 @@ class _CupertinoTextSelectionToolbarItemsRenderBox extends RenderBox with Contai
super.attach(owner);
// Attach slot children.
childToSlot.forEach((RenderBox child, _) {
for (final RenderBox child in slottedChildren.values) {
child.attach(owner);
});
}
}
@override
......@@ -1176,9 +1174,9 @@ class _CupertinoTextSelectionToolbarItemsRenderBox extends RenderBox with Contai
super.detach();
// Detach slot children.
childToSlot.forEach((RenderBox child, _) {
for (final RenderBox child in slottedChildren.values) {
child.detach();
});
}
}
@override
......
......@@ -2151,18 +2151,15 @@ class _RenderChipElement extends RenderObjectElement {
void insertRenderObjectChild(RenderObject child, _ChipSlot slot) {
assert(child is RenderBox);
_updateRenderObject(child, slot);
assert(renderObject.childToSlot.keys.contains(child));
assert(renderObject.slotToChild.keys.contains(slot));
assert(renderObject.children.keys.contains(slot));
}
@override
void removeRenderObjectChild(RenderObject child, _ChipSlot slot) {
assert(child is RenderBox);
assert(renderObject.childToSlot[child] == slot);
assert(renderObject.slotToChild[slot] == child);
assert(renderObject.children[slot] == child);
_updateRenderObject(null, slot);
assert(!renderObject.childToSlot.keys.contains(child));
assert(!renderObject.slotToChild.keys.contains(slot));
assert(!renderObject.children.keys.contains(slot));
}
@override
......@@ -2258,8 +2255,7 @@ class _RenderChip extends RenderBox {
enableAnimation.addListener(markNeedsPaint);
}
final Map<_ChipSlot, RenderBox> slotToChild = <_ChipSlot, RenderBox>{};
final Map<RenderBox, _ChipSlot> childToSlot = <RenderBox, _ChipSlot>{};
final Map<_ChipSlot, RenderBox> children = <_ChipSlot, RenderBox>{};
bool value;
bool isEnabled;
......@@ -2274,12 +2270,10 @@ class _RenderChip extends RenderBox {
RenderBox _updateChild(RenderBox oldChild, RenderBox newChild, _ChipSlot slot) {
if (oldChild != null) {
dropChild(oldChild);
childToSlot.remove(oldChild);
slotToChild.remove(slot);
children.remove(slot);
}
if (newChild != null) {
childToSlot[newChild] = slot;
slotToChild[slot] = newChild;
children[slot] = newChild;
adoptChild(newChild);
}
return newChild;
......
......@@ -645,18 +645,15 @@ class _RenderDecoration extends RenderBox {
_expands = expands;
static const double subtextGap = 8.0;
final Map<_DecorationSlot, RenderBox> slotToChild = <_DecorationSlot, RenderBox>{};
final Map<RenderBox, _DecorationSlot> childToSlot = <RenderBox, _DecorationSlot>{};
final Map<_DecorationSlot, RenderBox> children = <_DecorationSlot, RenderBox>{};
RenderBox _updateChild(RenderBox oldChild, RenderBox newChild, _DecorationSlot slot) {
if (oldChild != null) {
dropChild(oldChild);
childToSlot.remove(oldChild);
slotToChild.remove(slot);
children.remove(slot);
}
if (newChild != null) {
childToSlot[newChild] = slot;
slotToChild[slot] = newChild;
children[slot] = newChild;
adoptChild(newChild);
}
return newChild;
......@@ -1657,18 +1654,15 @@ class _RenderDecorationElement extends RenderObjectElement {
void insertRenderObjectChild(RenderObject child, _DecorationSlot slot) {
assert(child is RenderBox);
_updateRenderObject(child as RenderBox, slot);
assert(renderObject.childToSlot.keys.contains(child));
assert(renderObject.slotToChild.keys.contains(slot));
assert(renderObject.children.keys.contains(slot));
}
@override
void removeRenderObjectChild(RenderObject child, _DecorationSlot slot) {
assert(child is RenderBox);
assert(renderObject.childToSlot[child] == slot);
assert(renderObject.slotToChild[slot] == child);
assert(renderObject.children[slot] == child);
_updateRenderObject(null, slot);
assert(!renderObject.childToSlot.keys.contains(child));
assert(!renderObject.slotToChild.keys.contains(slot));
assert(!renderObject.children.keys.contains(slot));
}
@override
......
......@@ -1253,18 +1253,15 @@ class _ListTileElement extends RenderObjectElement {
void insertRenderObjectChild(RenderObject child, _ListTileSlot slot) {
assert(child is RenderBox);
_updateRenderObject(child as RenderBox, slot);
assert(renderObject.childToSlot.keys.contains(child));
assert(renderObject.slotToChild.keys.contains(slot));
assert(renderObject.children.keys.contains(slot));
}
@override
void removeRenderObjectChild(RenderObject child, _ListTileSlot slot) {
assert(child is RenderBox);
assert(renderObject.childToSlot[child] == slot);
assert(renderObject.slotToChild[slot] == child);
assert(renderObject.children[slot] == child);
_updateRenderObject(null, slot);
assert(!renderObject.childToSlot.keys.contains(child));
assert(!renderObject.slotToChild.keys.contains(slot));
assert(!renderObject.children.keys.contains(slot));
}
@override
......@@ -1299,18 +1296,15 @@ class _RenderListTile extends RenderBox {
// The minimum padding on the top and bottom of the title and subtitle widgets.
static const double _minVerticalPadding = 4.0;
final Map<_ListTileSlot, RenderBox> slotToChild = <_ListTileSlot, RenderBox>{};
final Map<RenderBox, _ListTileSlot> childToSlot = <RenderBox, _ListTileSlot>{};
final Map<_ListTileSlot, RenderBox> children = <_ListTileSlot, RenderBox>{};
RenderBox _updateChild(RenderBox oldChild, RenderBox newChild, _ListTileSlot slot) {
if (oldChild != null) {
dropChild(oldChild);
childToSlot.remove(oldChild);
slotToChild.remove(slot);
children.remove(slot);
}
if (newChild != null) {
childToSlot[newChild] = slot;
slotToChild[slot] = newChild;
children[slot] = newChild;
adoptChild(newChild);
}
return newChild;
......
......@@ -6079,6 +6079,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement {
@override
void removeRenderObjectChild(RenderObject child, dynamic slot) {
final RenderObjectWithChildMixin<RenderObject> renderObject = this.renderObject as RenderObjectWithChildMixin<RenderObject>;
assert(slot == null);
assert(renderObject.child == child);
renderObject.child = null;
assert(renderObject == this.renderObject);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment