submitSaveEventually static method

Future<ParseResponse?> submitSaveEventually({
  1. ParseClient? client,
  2. bool? autoSendSessionId,
})

Implementation

static Future<ParseResponse?> submitSaveEventually(
    {ParseClient? client, bool? autoSendSessionId}) async {
  // get client
  ParseClient localClient = client ??
      ParseCoreData().clientCreator(
          sendSessionId:
              autoSendSessionId ?? ParseCoreData().autoSendSessionId,
          securityContext: ParseCoreData().securityContext);

  // preparation ParseCoreData
  final CoreStore coreStore = ParseCoreData().getStore();

  // save
  // get json parse saved objects
  List<String>? listSaves =
      await coreStore.getStringList(keyParseStoreObjects);

  if (listSaves != null) {
    List<ParseObject> parseObjectList = [];
    for (var element in listSaves) {
      // decode json
      dynamic object = json.decode(element);
      parseObjectList
          .add(ParseObject(object[keyVarClassName]).fromJson(object));
    }

    // send parseObjects to server
    ParseResponse response =
        await ParseObject._saveChildren(parseObjectList, localClient);

    // if success clear all objects
    if (response.success) {
      coreStore.setStringList(keyParseStoreObjects, []);
    }

    return response;
  }

  return null;
}