improve image caching and disposal

This commit is contained in:
Fabian Freund
2026-01-14 05:21:48 +01:00
parent e691a97159
commit 057d14b6d9
12 changed files with 69 additions and 37 deletions
@@ -122,24 +122,24 @@ class TabStates extends _$TabStates {
Future<void> _onIconChange(IconChangeEvent event) async {
final IconChangeEvent(:tabId, :bytes) = event;
// Dispose old icon before replacing
state[tabId]?.icon?.dispose();
final image = await bytes.mapNotNull((bytes) => tryDecodeImage(bytes));
final current = state[tabId] ?? TabState.$default(tabId);
// Dispose old icon only after successfully creating new one
current.icon?.dispose();
state = {...state}..[tabId] = current.copyWith.icon(image);
}
Future<void> _onThumbnailChange(ThumbnailEvent event) async {
final ThumbnailEvent(:tabId, :bytes) = event;
// Dispose old thumbnail before replacing
state[tabId]?.thumbnail?.dispose();
final image = await bytes.mapNotNull((bytes) => tryDecodeImage(bytes));
final current = state[tabId] ?? TabState.$default(tabId);
// Dispose old thumbnail only after successfully creating new one
current.thumbnail?.dispose();
state = {...state}..[tabId] = current.copyWith.thumbnail(image);
}