createNew method
Adds a new instance of T, newData, to the repository.
If the creation is sucessful, will return true and the assigned id of the instance.
If the creation is not successful, will return false and null.
Note: userId is automatically applied to newData.
Implementation
Future<(bool, String?)> createNew(T newData) async {
if (!isInstanceValid(newData)) {
AppEventsDispatcher().publish(OperationFailedEvent(OperationType.create, service.repositoryId, newData));
return (false, null);
}
if (assignUserIdOnCreate) {
newData = newData.copyWith(userId: userId) as T;
}
_data.add(newData = newData.copyWith(id: await service.create(newData)) as T);
notifyListeners();
AppEventsDispatcher().publish(DataCreatedEvent(service.repositoryId, newData));
return (true, newData.id);
}