write method
void
write({})
Implementation
void write({String? imageId, String? imageUri, required Uint8List data, required String mimeType}) {
final key = _key(imageId: imageId, imageUri: imageUri);
if (key == null || data.isEmpty || data.lengthInBytes > maximumBytes) {
return;
}
final previous = _entries.remove(key);
if (previous != null) {
_cachedBytes -= previous.data.lengthInBytes;
}
_entries[key] = ThreadAttachmentImageData(data: data, mimeType: mimeType);
_cachedBytes += data.lengthInBytes;
while (_cachedBytes > maximumBytes && _entries.isNotEmpty) {
final oldestKey = _entries.keys.first;
final removed = _entries.remove(oldestKey);
if (removed != null) {
_cachedBytes -= removed.data.lengthInBytes;
}
}
}