removeItem method
- int index,
- AnimatedRemovedItemBuilder builder, {
- Duration duration = _kDuration,
inherited
Remove the item at index
and start an animation that will be passed to
builder
when the item is visible.
If using AnimatedList.separated, the animation will also be passed to the
corresponding separator's AnimatedList.removedSeparatorBuilder
.
Items are removed immediately. After an item has been removed, its index
will no longer be passed to the builder
. However, the
item will still appear for duration
and during that time
builder
must construct its widget as needed.
This method's semantics are the same as Dart's List.remove method: it
decreases the length of items by one and shifts all items at or before
index
towards the beginning of the list of items.
See also:
- AnimatedRemovedItemBuilder, which describes the arguments to the
builder
argument.
Implementation
void removeItem(int index, AnimatedRemovedItemBuilder builder, { Duration duration = _kDuration }) {
final AnimatedItemBuilder? removedSeparatorBuilder = widget.removedSeparatorBuilder;
if (removedSeparatorBuilder == null) {
// There are no separators. Remove only the item.
_sliverAnimatedMultiBoxKey.currentState!.removeItem(index, builder, duration: duration);
} else {
final int itemIndex = _computeItemIndex(index);
// Remove the item
_sliverAnimatedMultiBoxKey.currentState!.removeItem(itemIndex, builder, duration: duration);
if (_itemsCount > 1) {
if (itemIndex == _itemsCount - 1) {
// The item was removed from the end of the list, so the separator to remove is the one at `last index` - 1.
_sliverAnimatedMultiBoxKey.currentState!.removeItem(itemIndex - 1, _toRemovedItemBuilder(removedSeparatorBuilder, index - 1), duration: duration);
} else {
// The item was removed from the middle or beginning of the list,
// so the corresponding separator took its place and needs to be removed at `itemIndex`.
_sliverAnimatedMultiBoxKey.currentState!.removeItem(itemIndex, _toRemovedItemBuilder(removedSeparatorBuilder, index), duration: duration);
}
}
}
}