save method

Future<ParseResponse> save({
  1. dynamic context,
})

Saves the current object online.

If the object not saved yet, this will create it. Otherwise, it will send the updated object to the server.

This will save any nested(child) object in this object. So you do not need to each one of them manually.

Example of saving child and parent objects using save():

final dietPlan = ParseObject('Diet_Plans')..set('Fat', 15);
final plan = ParseObject('Plan')..set('planName', 'John.W');
dietPlan.set('plan', plan);

// the save function will create the nested(child) object first and then
// attempts to save the parent object.
//
// using create in this situation will throw an error, because the child
// object is not saved/created yet and you need to create it manually
await dietPlan.save();

print(plan.objectId); // DLde4rYA8C
print(dietPlan.objectId); // RGd4fdEUB

The same principle works with ParseRelation

Its safe to call this function aging if an error occurred while saving.

Prefer using save over update and create

Implementation

Future<ParseResponse> save({dynamic context}) async {
  final ParseResponse childrenResponse = await _saveChildren(this, _client);
  if (childrenResponse.success) {
    ParseResponse? response;
    if (objectId == null) {
      response = await create(context: context);
    } else if (_isDirty(false)) {
      response = await update(context: context);
    }

    if (response != null) {
      if (response.success) {
        _savingChanges.clear();
      } else {
        _revertSavingChanges();
      }
      return response;
    }
  }
  return childrenResponse;
}