update method

Future<bool> update()

Updates _data inside the repository. If the creation is sucessful, will return true. Otherwise, false. Note: userId is automatically applied to _data.

Implementation

Future<bool> update() async {
  if (_data == null || !isInstanceValid(_data as T)) {
    return false;
  }

  if (!isInstanceValid(_data!)) {
    AppEventsDispatcher().publish(OperationFailedEvent(OperationType.update, service.repositoryId, _data!));
    return false;
  }

  if (assignUserIdOnUpdate) {
    _data = _data!.copyWith(userId: userId) as T;
  }

  await service.update(_data!);

  notifyListeners();
  AppEventsDispatcher().publish(DataUpdatedEvent(service.repositoryId, _data!));

  return true;
}