@@ -8,27 +8,28 @@ import 'package:school_data_hub_client/school_data_hub_client.dart';
88import 'package:school_data_hub_flutter/app_utils/custom_encrypter.dart' ;
99import 'package:school_data_hub_flutter/common/services/notification_service.dart' ;
1010
11+ DefaultCacheManager get _cacheManager => di <DefaultCacheManager >();
12+ NotificationService get _notificationService => di <NotificationService >();
13+
1114Future <File ?> downloadAndDecryptFile ({
1215 required String documentId,
1316 required bool decrypt,
1417}) async {
15- final cacheManager = di <DefaultCacheManager >();
16- final notificationService = di <NotificationService >();
17-
1818 // Check cache
19- final fileInfo = await cacheManager .getFileFromCache (documentId);
19+ final fileInfo = await _cacheManager .getFileFromCache (documentId);
2020
2121 if (fileInfo != null && await fileInfo.file.exists ()) {
2222 if (! decrypt) {
2323 return fileInfo.file;
2424 }
2525
2626 final fileBytes = await fileInfo.file.readAsBytes ();
27- final (: bytes, : wasLegacy) =
28- await customEncrypter.decryptFileBytesAsync (fileBytes);
27+ final (: bytes, : wasLegacy) = await customEncrypter.decryptFileBytesAsync (
28+ fileBytes,
29+ );
2930
3031 if (wasLegacy) {
31- _migrateToNewFormat (documentId, bytes, cacheManager );
32+ _migrateToNewFormat (documentId, bytes);
3233 }
3334
3435 final tempDir = await Directory .systemTemp.createTemp ();
@@ -41,12 +42,12 @@ Future<File?> downloadAndDecryptFile({
4142 }
4243
4344 // Download
44- notificationService .apiRunning (true );
45+ _notificationService .apiRunning (true );
4546 final ByteData ? byteData = await di <Client >().files.getImage (documentId);
46- notificationService .apiRunning (false );
47+ _notificationService .apiRunning (false );
4748
4849 if (byteData == null ) {
49- notificationService .showSnackBar (
50+ _notificationService .showSnackBar (
5051 NotificationType .error,
5152 'Fehler beim Laden der Datei' ,
5253 );
@@ -55,7 +56,7 @@ Future<File?> downloadAndDecryptFile({
5556
5657 Uint8List fileBytes = byteData.buffer.asUint8List ();
5758 // Cache it
58- await cacheManager .putFile (documentId, fileBytes);
59+ await _cacheManager .putFile (documentId, fileBytes);
5960
6061 if (! decrypt) {
6162 final tempDir = await Directory .systemTemp.createTemp ();
@@ -65,11 +66,12 @@ Future<File?> downloadAndDecryptFile({
6566 return tempFile;
6667 }
6768
68- final (: bytes, : wasLegacy) =
69- await customEncrypter.decryptFileBytesAsync (fileBytes);
69+ final (: bytes, : wasLegacy) = await customEncrypter.decryptFileBytesAsync (
70+ fileBytes,
71+ );
7072
7173 if (wasLegacy) {
72- _migrateToNewFormat (documentId, bytes, cacheManager );
74+ _migrateToNewFormat (documentId, bytes);
7375 }
7476
7577 final tempDir = await Directory .systemTemp.createTemp ();
@@ -83,20 +85,17 @@ Future<File?> downloadAndDecryptFile({
8385
8486/// Fire-and-forget: re-encrypt [plainBytes] in the new format, update the
8587/// server file, and refresh the local cache — all without blocking the caller.
86- void _migrateToNewFormat (
87- String documentId,
88- Uint8List plainBytes,
89- DefaultCacheManager cacheManager,
90- ) {
88+ void _migrateToNewFormat (String documentId, Uint8List plainBytes) {
9189 Future (() async {
9290 try {
9391 final newEncrypted = customEncrypter.encryptTheseBytes (plainBytes);
9492 final byteData = ByteData .sublistView (newEncrypted);
95- final ok = await di <Client >()
96- .files
97- .replaceEncryptedFileBytes (documentId, byteData);
93+ final ok = await di <Client >().files.replaceEncryptedFileBytes (
94+ documentId,
95+ byteData,
96+ );
9897 if (ok) {
99- await cacheManager .putFile (documentId, newEncrypted);
98+ await _cacheManager .putFile (documentId, newEncrypted);
10099 }
101100 } catch (_) {
102101 // Migration is best-effort; silently ignore failures.
0 commit comments