This repository has been archived on 2023-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
meincantor-app/lib/cache_manager.dart
Denys Konovalov ba75ce8d6d ==1.0.0==
- removed obsolete deps
- fixed many issues
- improved features
- added:
  * favourites
  * account console
  * push notifications
  * background sync
  * improved settings
2021-12-19 22:20:56 +01:00

23 lines
847 B
Dart

import 'dart:convert';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:shared_preferences/shared_preferences.dart';
Future<String> getCachedTimetable(String ext, String? presetClassNum) async {
SharedPreferences prefs = await SharedPreferences.getInstance();
String classNum;
if (presetClassNum != null) {
classNum = presetClassNum.replaceAll("/", "_");
} else if (prefs.getString('class_num') != null) {
classNum = prefs.getString('class_num')!.replaceAll("/", "_");
} else {
classNum = '05_1';
}
var apiKey = prefs.getString('api_key');
var headers = {"x-api-key": "$apiKey"};
var file = await DefaultCacheManager().getSingleFile(
"https://mein.cantorgymnasium.de/api/timetable/$ext/$classNum",
headers: headers);
return (utf8.decode(await file.readAsBytes()));
}