retryFailedrequests method
Startet den Upload, ggf. mit fortlaufender Progress-Callback.
Implementation
Future<bool> retryFailedrequests({
required BuildContext context,
void Function(double overallProgress, bool? success, String? currentInspId,
double currentInspProgress, String etaString)?
onProgress,
}) async {
debugPrint('retry failed requests started');
// Prüfe zuerst alle Berechtigungen
if (!await _checkPermissions(context)) {
return false;
}
try {
// Check Internet
await API().tryNetwork(requestType: Helper.SimulatedRequestType.PUT);
} catch (e) {
showToast('Keine funktionierende Internetverbindung');
return false;
}
// Notifications erlauben?
bool notificationsAllowed = await allowNotificationGuard(
context,
'Wir können dir eine Benachrichtigung über den Sync-Fortschritt senden.',
);
bool finalSuccess = false;
final progressReceiver = ReceivePort();
final isolateInputData = _RetryFailedRequestsIsolateInput(
rootIsolateToken: RootIsolateToken.instance!,
progressSender: progressReceiver.sendPort,
notificationsAllowed: notificationsAllowed,
);
final subscription = progressReceiver.listen((msg) {
// msg: (double overall, bool? succ, String? inspId, double inspProg, String eta)
final (overall, maybeSuccess, inspId, inspProg, etaStr) =
msg as (double, bool?, String?, double, String);
if (maybeSuccess != null) {
// => Upload beendet
finalSuccess = maybeSuccess;
progressReceiver.close();
} else {
// => Zwischenschritt
onProgress?.call(overall, null, inspId, inspProg, etaStr);
}
});
// Statt über ein echtes Isolate (spawn) auszulagern,
// rufen wir hier direkt die Upload-Logik asynchron auf:
await _retryFailedRequestsIsolate(isolateInputData);
// Warten, bis sämtliche Nachrichten gelesen wurden:
await subscription.asFuture();
// Letztes "onProgress", um finalen Erfolg zu signalisieren:
onProgress?.call(1.0, finalSuccess, null, 1.0, '');
return finalSuccess;
}