reorderRoots method
Reorders the root nodes to match orderedKeys.
orderedKeys must contain exactly the current live (non-pending-deletion)
root keys. Expansion state, animation state, and measured extents are
preserved. Pending-deletion roots are appended after the live roots.
Implementation
void reorderRoots(List<TKey> orderedKeys) {
final pendingRoots = <TKey>[];
final liveRootSet = <TKey>{};
for (final k in _roots) {
if (_isPendingDeletion(k)) {
pendingRoots.add(k);
} else {
liveRootSet.add(k);
}
}
// Validate in all build modes: an `assert` here would be stripped in
// release and silently corrupt `_roots` (duplicated entries, lost subtrees,
// references to unknown keys).
if (orderedKeys.length != liveRootSet.length ||
orderedKeys.toSet().length != orderedKeys.length ||
!liveRootSet.containsAll(orderedKeys)) {
throw ArgumentError.value(
orderedKeys,
"orderedKeys",
"must contain exactly the current live root keys with no duplicates",
);
}
_roots
..clear()
..addAll(orderedKeys)
..addAll(pendingRoots);
_markVisibleOrderDirty();
// Pure reorder: positions change but no row's builder output does
// (nodeBuilder signature takes (context, key, depth) — no index). The
// sliver's layout repositions elements in place.
_notifyStructural(affectedKeys: const {});
}