createNew method

Future<(bool, String?)> createNew(
  1. T newData
)

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)) {
    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();

  return (true, newData.id);
}