refreshInspectionForDownload method

Future<InspectionLocation> refreshInspectionForDownload(
  1. InspectionLocation current
)

Implementation

Future<InspectionLocation> refreshInspectionForDownload(
  InspectionLocation current,
) async {
  await API().tryNetwork(requestType: Helper.SimulatedRequestType.GET);
  final request =
      API().remote.getNextDatapoint<InspectionLocation, WithOffline?>(
            null,
            preloadFullImages: false,
          );
  final response = await API().remote.postJSON(request.rd);
  if (response is! http.Response) {
    throw StateError(
      'Inspektionen konnten nicht direkt vom Server geladen werden',
    );
  }
  final inspections = await request.parser(response);
  final refreshed =
      selectRefreshedInspectionForDownload(current, inspections);
  if (refreshed == null) {
    throw StateError(
      'Inspektion ${current.pjNr}/${current.stONr} konnte nicht aktualisiert werden',
    );
  }
  preserveExistingDocumentsForDownload(current, refreshed);
  return refreshed;
}