syncFromRemote<T extends VasatModel<T>> method

Future<bool> syncFromRemote<T extends VasatModel<T>>(
  1. VasatFromJsonFactory<T> factory, {
  2. Map<String, String>? params,
  3. bool updatesOnly = true,
})

Implementation

Future<bool> syncFromRemote<T extends VasatModel<T>>(VasatFromJsonFactory<T> factory, {Map<String, String>? params, bool updatesOnly = true}) async {

  // Get the vasat object name from the factory. We simply create an empty object to call the getObjectName().
  var vasatObjectName = factory({}).getObjectName();

  return storageProvider.getObjectLastTimestamp( vasatObjectName )
    .then((timestamp) {
      if (updatesOnly && timestamp != null) {
        if (params == null) params = {};
        params!["dateUpdated"] = ">$timestamp";
      }
      return searchObject<T>(factory, params: params, updateTimestamp: true);
    }).then((objList) => storageProvider.saveObjects<T>(objList));
}