fix: offload image compression to background isolate via compute()
Co-authored-by: derkauzigekoala <79001016+derkauzigekoala@users.noreply.github.com>
This commit is contained in:
parent
8a3bda71e6
commit
3f0c7944b8
1 changed files with 6 additions and 0 deletions
|
|
@ -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.');
|
||||
|
|
|
|||
Loading…
Reference in a new issue