@@ -42,17 +42,17 @@ class FileHelper {
4242 void addToCache (Uint8List imageData, String filename) {
4343 int key;
4444 if (imageCacheProvider.availableKeys.isNotEmpty) {
45- // Reuse the lowest available key
4645 key = imageCacheProvider.availableKeys.first;
4746 imageCacheProvider.availableKeys.remove (key);
4847 } else {
49- // Assign a new key
5048 key = imageCacheProvider.imageCache.length;
5149 while (imageCacheProvider.imageCache.containsKey (key)) {
5250 key++ ;
5351 }
5452 }
53+
5554 imageCacheProvider.imageCache[[filename, key]] = imageData;
55+ imageCacheProvider.notify ();
5656 }
5757
5858 Future <void > generateClipartCache () async {
@@ -76,7 +76,7 @@ class FileHelper {
7676 decodedData.cast <List <dynamic >>();
7777 List <List <int >> intImageData =
7878 imageData.map ((list) => list.cast <int >()).toList ();
79- imageCacheProvider.clipartsCache[file.path. split ( '/' ) .last] =
79+ imageCacheProvider.clipartsCache[file.uri.pathSegments .last] =
8080 intImageData;
8181 }
8282 } catch (e) {
@@ -137,11 +137,18 @@ class FileHelper {
137137
138138 // Read all files, parse the 2D lists, and add to cache
139139 Future <void > loadImageCacheFromFiles () async {
140- generateClipartCache ();
141- getBadgeDataFiles ();
140+ await generateClipartCache ();
141+ await getBadgeDataFiles ();
142142 final directory = await getApplicationDocumentsDirectory ();
143143 final List <FileSystemEntity > files = directory.listSync ();
144144
145+ files.sort ((a, b) {
146+ if (a is File && b is File ) {
147+ return b.lastModifiedSync ().compareTo (a.lastModifiedSync ());
148+ }
149+ return 0 ;
150+ });
151+
145152 for (var file in files) {
146153 if (file is File &&
147154 file.path.endsWith ('.json' ) &&
@@ -152,7 +159,7 @@ class FileHelper {
152159 final List <dynamic > decodedData = jsonDecode (content);
153160 final List <List <dynamic >> imageData =
154161 decodedData.cast <List <dynamic >>();
155- await _addImageDataToCache (imageData, file.path. split ( '/' ) .last);
162+ await _addImageDataToCache (imageData, file.uri.pathSegments .last);
156163 }
157164 }
158165 }
@@ -308,7 +315,7 @@ class FileHelper {
308315 // Defensive: Only add if valid structure
309316 if (jsonData.containsKey ('messages' ) &&
310317 jsonData['messages' ] is List ) {
311- badgeDataList.add (MapEntry (file.path. split ( '/' ) .last, jsonData));
318+ badgeDataList.add (MapEntry (file.uri.pathSegments .last, jsonData));
312319 } else {
313320 logger.i ('Skipping invalid badge file: ${file .path }' );
314321 }
@@ -364,7 +371,8 @@ class FileHelper {
364371 File file = File (filePath);
365372 if (await file.exists ()) {
366373 // Use share_plus to share the file
367- final result = await Share .shareXFiles ([XFile (filePath)]);
374+ final result = await SharePlus .instance
375+ .share (ShareParams (files: [XFile (filePath)]));
368376 if (result.status == ShareResultStatus .success) {
369377 logger.i ('File shared successfully' );
370378 } else {
0 commit comments