insertItem method
inherited
Insert an item at index
and start an animation that will be passed
to AnimatedGrid.itemBuilder
or AnimatedList.itemBuilder
when the item
is visible.
If using AnimatedList.separated the animation will also be passed
to separatorBuilder
.
This method's semantics are the same as Dart's List.insert method: it
increases the length of the list of items by one and shifts
all items at or after index
towards the end of the list of items.
Implementation
void insertItem(int index, { Duration duration = _kDuration }) {
if (widget.removedSeparatorBuilder == null) {
_sliverAnimatedMultiBoxKey.currentState!.insertItem(index, duration: duration);
} else {
final int itemIndex = _computeItemIndex(index);
_sliverAnimatedMultiBoxKey.currentState!.insertItem(itemIndex, duration: duration);
if (_itemsCount > 1) {
// Because `insertItem` moves the items after the index, we need to insert the separator
// at the same index as the item. If there is only one item, we don't need to insert a separator.
_sliverAnimatedMultiBoxKey.currentState!.insertItem(itemIndex, duration: duration);
}
}
}