fix: offload image compression to background isolate via compute()

Co-authored-by: derkauzigekoala <79001016+derkauzigekoala@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-07 22:49:11 +00:00
parent 8a3bda71e6
commit 3f0c7944b8

View file

@ -113,6 +113,12 @@ class StorageService {
static Future<Uint8List> _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.');