put method

  1. @override
Future<void> put(
  1. Iterable<T> items, {
  2. int compare(
    1. T,
    2. T
    )?,
})
override

Adds the provided items to this PageProvider.

Implementation

@override
Future<void> put(Iterable<T> items, {int Function(T, T)? compare}) async {
  final bool toView = compare == null;

  for (var item in items) {
    _account(OperationKind.added, onKey(item));
  }

  if (toView) {
    for (var item in items) {
      final int i = _list.indexWhere((e) => onKey(e) == onKey(item));
      if (i != -1) {
        _list[i] = item;
      } else {
        _list.insertAfter(item, (e) => this.compare?.call(e, item) == 1);
      }
    }

    if (_after != null) {
      _after = _after! + items.length;
    }
  }

  await add?.call(items, toView: toView);
}