Matthias Nott
2026-03-25 d6cf9469aa0462d1b8313cc85907176eee1214a2
lib/widgets/message_bubble.dart
....@@ -270,13 +270,17 @@
270270 return const Text('Image unavailable');
271271 }
272272
273
- // Cache decoded bytes to prevent flicker on rebuild
274
- final bytes = _imageCache.putIfAbsent(message.id, () {
273
+ // Cache decoded bytes to prevent flicker on rebuild; evict oldest if over 50 entries
274
+ if (!_imageCache.containsKey(message.id)) {
275
+ if (_imageCache.length >= 50) {
276
+ _imageCache.remove(_imageCache.keys.first);
277
+ }
275278 final raw = message.imageBase64!;
276
- return Uint8List.fromList(base64Decode(
279
+ _imageCache[message.id] = Uint8List.fromList(base64Decode(
277280 raw.contains(',') ? raw.split(',').last : raw,
278281 ));
279
- });
282
+ }
283
+ final bytes = _imageCache[message.id]!;
280284
281285 return Column(
282286 crossAxisAlignment: CrossAxisAlignment.start,