updateFirstWhereOrNull method
T?
updateFirstWhereOrNull(})
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;
}