moveItem method
Repositions itemKey, either across sections or within its own.
• toSection non-null → reparents the item under that section.
With index it lands at that position; without, it is
appended.
• toSection null, index non-null → reorders the item within
its current section to index.
• both null → no-op.
When animate is true (the default), a cross-section reparent runs
a paint-only FLIP slide on the moved row from its old painted
position to its new one, using slideDuration / slideCurve.
Both default to the controller's animationDuration /
animationCurve so the slide stays in sync with the inserts /
removes / expands / collapses that may compose with it inside the
same runBatch.
In-section reorders are pure repositioning ops that never animate
regardless of animate — neighbouring rows shift in place, the
underlying TreeController.reorderChildren does not produce
per-row enter/exit animations.
Implementation
void moveItem(
K itemKey, {
K? toSection,
int? index,
bool animate = true,
Duration? slideDuration,
Curve? slideCurve,
}) {
_checkNotDisposed();
_requireItem(itemKey, "moveItem");
if (toSection != null) {
_requireSection(toSection, "moveItem(toSection)");
_tree.moveNode(
ItemKey<K>(itemKey),
SectionKey<K>(toSection),
index: index,
animate: animate,
slideDuration: slideDuration ?? _tree.animationDuration,
slideCurve: slideCurve ?? _tree.animationCurve,
);
return;
}
if (index == null) {
// Neither a reparent target nor a reorder index — nothing to do.
return;
}
if (_tree.isPendingDeletion(ItemKey<K>(itemKey))) {
_throwMissing("moveItem", "item $itemKey is being removed");
}
final parentKey = sectionOf(itemKey);
if (parentKey == null) {
_throwMissing("moveItem", "item $itemKey has no parent section");
}
// Use the LIVE list — `reorderItems` → `_tree.reorderChildren`
// validates against the live child set (excludes pending-deletion).
final siblings = itemKeysOf(parentKey)..remove(itemKey);
final clamped = index.clamp(0, siblings.length);
siblings.insert(clamped, itemKey);
reorderItems(parentKey, siblings);
}