update method
Updates _data
inside the repository.
If the creation is sucessful, will return true
. Otherwise, false
.
Note: userId is automatically applied to existingData
.
Implementation
Future<bool> update(T existingData) async {
if (_data.any((element) => element.id == existingData.id) ||
!isInstanceValid(existingData)) {
return false;
}
if (assignUserIdOnUpdate) {
existingData = existingData.copyWith(userId: userId) as T;
}
_data.replace(existingData);
await _service.update(existingData);
notifyListeners();
return true;
}