updateFirstWhereOrNull method

T? updateFirstWhereOrNull(
  1. bool test(
    1. T value
    ),
  2. T update(
    1. T value
    ), {
  3. bool doNotifyListeners = true,
})

Updates the first value that meets the criteria with given update.

Implementation

T? updateFirstWhereOrNull(
  bool Function(T value) test,
  T Function(T value) update, {
  bool doNotifyListeners = true,
}) {
  int? localIndex;
  T? toBeUpdated;
  for (int index = 0; index < _value.length; index++) {
    final value = _value[index];
    if (test(value)) {
      localIndex = index;
      toBeUpdated = value;
    }
  }
  if (toBeUpdated != null) {
    final updated = update(toBeUpdated);
    _value[localIndex!] = updated;
    if (doNotifyListeners) {
      notifyListeners();
    }
    return updated;
  }
  return null;
}