diff --git a/packages/flutter/lib/src/cupertino/text_selection.dart b/packages/flutter/lib/src/cupertino/text_selection.dart index 6ba283f19b..95c9ca83c5 100644 --- a/packages/flutter/lib/src/cupertino/text_selection.dart +++ b/packages/flutter/lib/src/cupertino/text_selection.dart @@ -748,7 +748,6 @@ class _CupertinoTextSelectionToolbarItemsElement extends RenderObjectElement { List _children; final Map<_CupertinoTextSelectionToolbarItemsSlot, Element> slotToChild = <_CupertinoTextSelectionToolbarItemsSlot, Element>{}; - final Map childToSlot = {}; // 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)) diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index 7fdf00998a..00e187298c 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -2067,7 +2067,6 @@ class _RenderChipElement extends RenderObjectElement { _RenderChipElement(_ChipRenderWidget chip) : super(chip); final Map<_ChipSlot, Element> slotToChild = <_ChipSlot, Element>{}; - final Map childToSlot = {}; @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; } } diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 82f2c1dac0..3ab3045822 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -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 childToSlot = {}; @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) { diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 48855be2e3..835963ffb7 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -1164,7 +1164,6 @@ class _ListTileElement extends RenderObjectElement { _ListTileElement(_ListTile widget) : super(widget); final Map<_ListTileSlot, Element> slotToChild = <_ListTileSlot, Element>{}; - final Map childToSlot = {}; @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; } } diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 4165ffc68c..64d42e19a4 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -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].