replaceFirstItemWhere method

bool replaceFirstItemWhere({
  1. required bool test(
    1. T item
    ),
  2. required T newItem,
})

Replaces first item that matches the test with a newItem.

Implementation

bool replaceFirstItemWhere({
  required bool Function(T item) test,
  required T newItem,
}) {
  var index = _newItems.indexWhere(test);
  if (index != -1) {
    _newItems[index] = newItem;
    notifyListeners();
    return true;
  }
  index = _oldItems.indexWhere(test);
  if (index != -1) {
    _oldItems[index] = newItem;
    notifyListeners();
    return true;
  }
  return false;
}