// Update the top of the list. while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { finalElement? oldChild = replaceWithNullIfForgotten(oldChildren[oldChildrenTop]); final Widget newWidget = newWidgets[newChildrenTop];
// Scan the bottom of the list. while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { finalElement? oldChild = replaceWithNullIfForgotten(oldChildren[oldChildrenBottom]); final Widget newWidget = newWidgets[newChildrenBottom];
// Scan the old children in the middle of the list. finalbool haveOldChildren = oldChildrenTop <= oldChildrenBottom; Map<Key, Element>? oldKeyedChildren; if (haveOldChildren) { oldKeyedChildren = <Key, Element>{}; while (oldChildrenTop <= oldChildrenBottom) { finalElement? oldChild = replaceWithNullIfForgotten(oldChildren[oldChildrenTop]);
if (oldChild != null) { if (oldChild.widget.key != null) oldKeyedChildren[oldChild.widget.key!] = oldChild; else deactivateChild(oldChild); } oldChildrenTop += 1; } }
// Update the middle of the list. while (newChildrenTop <= newChildrenBottom) { Element? oldChild; final Widget newWidget = newWidgets[newChildrenTop]; if (haveOldChildren) { final Key? key = newWidget.key; if (key != null) { oldChild = oldKeyedChildren![key]; if (oldChild != null) { if (Widget.canUpdate(oldChild.widget, newWidget)) { // we found a match! // remove it from oldKeyedChildren so we don't unsync it later oldKeyedChildren.remove(key); } else { // Not a match, let's pretend we didn't see it for now. oldChild = null; } } } }
// Update the bottom of the list. while ((oldChildrenTop <= oldChildrenBottom) && (newChildrenTop <= newChildrenBottom)) { finalElement oldChild = oldChildren[oldChildrenTop];
final Widget newWidget = newWidgets[newChildrenTop];
// Clean up any of the remaining middle nodes from the old list. if (haveOldChildren && oldKeyedChildren!.isNotEmpty) { for (finalElement oldChild in oldKeyedChildren.values) { if (forgottenChildren == null || !forgottenChildren.contains(oldChild)) deactivateChild(oldChild); } }