diff --git a/packages/flutter/lib/src/cupertino/text_selection.dart b/packages/flutter/lib/src/cupertino/text_selection.dart index fad1d674fa..6ba283f19b 100644 --- a/packages/flutter/lib/src/cupertino/text_selection.dart +++ b/packages/flutter/lib/src/cupertino/text_selection.dart @@ -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 childToSlot = {}; + 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 diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index f0f6c90b0f..7fdf00998a 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart @@ -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 childToSlot = {}; + 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; diff --git a/packages/flutter/lib/src/material/input_decorator.dart b/packages/flutter/lib/src/material/input_decorator.dart index 520a32e86f..82f2c1dac0 100644 --- a/packages/flutter/lib/src/material/input_decorator.dart +++ b/packages/flutter/lib/src/material/input_decorator.dart @@ -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 childToSlot = {}; + 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 diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index d1ecc8a0bd..48855be2e3 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -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 childToSlot = {}; + 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; diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 81991079c9..4165ffc68c 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -6079,6 +6079,7 @@ class SingleChildRenderObjectElement extends RenderObjectElement { @override void removeRenderObjectChild(RenderObject child, dynamic slot) { final RenderObjectWithChildMixin renderObject = this.renderObject as RenderObjectWithChildMixin; + assert(slot == null); assert(renderObject.child == child); renderObject.child = null; assert(renderObject == this.renderObject);