WIP high education graduation calculator

This commit is contained in:
2024-03-23 15:42:31 +01:00
parent e7192008c0
commit c4f5be2205
5 changed files with 179 additions and 5 deletions

View File

@ -1,9 +1,9 @@
import 'dart:convert';
import 'dart:developer';
import 'package:localstore/localstore.dart';
import 'apiResponse.dart';
import 'webuntis/webuntisError.dart';
abstract class RequestCache<T extends ApiResponse?> {
static const int cacheNothing = 0;
@ -30,16 +30,18 @@ abstract class RequestCache<T extends ApiResponse?> {
if(renew == null || !renew!) return;
}
T? newValue;
try {
T newValue = await onLoad();
onUpdate(newValue);
newValue = await onLoad();
onUpdate(newValue as T);
Localstore.instance.collection(file).doc(document).set({
"json": jsonEncode(newValue),
"lastupdate": DateTime.now().millisecondsSinceEpoch
});
} on WebuntisError catch(e) {
onError(e);
} catch(e) {
log("Error while fetching/ parsing. Raw server response: ${newValue?.rawResponse.body ?? "no response"}");
onError(Exception(e.toString()));
}
}