createNew method
Adds a new instance of T, newData, to the repository, and replaces _data.
If the creation is successful, 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 = newData.copyWith(id: await service.create(newData)) as T;
notifyListeners();
AppEventsDispatcher().publish(DataCreatedEvent(service.repositoryId, _data!));
return (true, _data!.id);
}