From 3f0c7944b8e41e5b71ff67a2cd27b173603ca9db Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 7 Mar 2026 22:49:11 +0000 Subject: [PATCH] fix: offload image compression to background isolate via compute() Co-authored-by: derkauzigekoala <79001016+derkauzigekoala@users.noreply.github.com> --- lib/services/storage_service.dart | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/services/storage_service.dart b/lib/services/storage_service.dart index 73c3707..8cafb98 100644 --- a/lib/services/storage_service.dart +++ b/lib/services/storage_service.dart @@ -113,6 +113,12 @@ class StorageService { static Future _compressImage(File source) async { final bytes = await source.readAsBytes(); + return compute(_compressImageBytes, bytes); + } + + /// Performs CPU-intensive image decoding, resizing, and JPEG encoding. + /// Runs in a background isolate via [compute] to avoid blocking the UI thread. + static Uint8List _compressImageBytes(Uint8List bytes) { final decoded = img.decodeImage(bytes); if (decoded == null) { throw Exception('Invalid image file.');