removeAllItems method

void removeAllItems(
  1. AnimatedRemovedItemBuilder builder, {
  2. Duration duration = _kDuration,
})
inherited

Remove all the items and start an animation that will be passed to builder when the items are visible.

If using AnimatedList.separated, the animation will also be passed to the corresponding separator's AnimatedList.removedSeparatorBuilder.

Items are removed immediately. However, the items 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.clear method: it removes all the items in the list.

See also:

Implementation

void removeAllItems(AnimatedRemovedItemBuilder builder, { Duration duration = _kDuration }) {
  final AnimatedItemBuilder? removedSeparatorBuilder = widget.removedSeparatorBuilder;
  if (removedSeparatorBuilder == null) {
    // There are no separators. We can remove all items with the same builder.
    _sliverAnimatedMultiBoxKey.currentState!.removeAllItems(builder, duration: duration);
    return;
  }

  // There are separators. We need to remove items and separators separately
  // with the corresponding builders.
  for (int index = _itemsCount - 1; index >= 0 ; index--) {
    if (index.isEven) {
      _sliverAnimatedMultiBoxKey.currentState!.removeItem(index, builder, duration: duration);
    } else {
      // The index of the separator's corresponding item
      final int itemIndex = index ~/ 2;
      _sliverAnimatedMultiBoxKey.currentState!.removeItem(index, _toRemovedItemBuilder(removedSeparatorBuilder, itemIndex), duration: duration);
    }
  }
}