flutter_image_compress
flutter_image_compress copied to clipboard
in Isolate, i
Flutter_image Compress is not working in isolates i am calling this method under isolates
static void compressImageByPercentage(IsolateThreadModel isolateThreadModel)async{
// Uint8List bytes = File(isolateThreadModel.inputImagePath!).readAsBytesSync();
BackgroundIsolateBinaryMessenger.ensureInitialized;
Uint8List compressedData = await FlutterImageCompress.compressWithList(
isolateThreadModel.bytes!,
quality: isolateThreadModel.percentage!,
);
isolateThreadModel.sendPort!
.send(compressedData);
}
Isolate
_isolate = await Isolate.spawn(compressImageByPercentage, isolateThreadModel);
_receivePort!.listen(_recievedProcessedDataByCompressed, onDone: () {
print("done!");
});
i am getting below error only when this package call
[ERROR:flutter/runtime/dart_isolate.cc(1098)] Unhandled exception:
E/flutter (18427): Bad state: The BackgroundIsolateBinaryMessenger.instance value is invalid until BackgroundIsolateBinaryMessenger.ensureInitialized is executed.
E/flutter (18427): #0 BackgroundIsolateBinaryMessenger.instance (package:flutter/src/services/_background_isolate_binary_messenger_io.dart:27:7)
E/flutter (18427): #1 _findBinaryMessenger (package:flutter/src/services/platform_channel.dart:135:42)
E/flutter (18427): #2 MethodChannel.binaryMessenger (package:flutter/src/services/platform_channel.dart:273:56)
E/flutter (18427): #3 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:15)
E/flutter (18427): #4 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:491:12)
E/flutter (18427): #5 FlutterImageCompress.compressWithList (package:flutter_image_compress/flutter_image_compress.dart:64:35)
E/flutter (18427): <asynchronous suspension>
E/flutter (18427): #6 imageCompressorController.compressImageByPercentage (package:imageresizer/controller/imagecompressorcontroller.dart:34:30)
E/flutter (18427): <asynchronous suspension>
i have resolved using other FlutterIsolate package, now this package works perfectly fine.
Hey @karamatpkid, what did you do to fix the issue with compressing on isolates?
I were using Isolate.spawn . now I am compressing image using flutter_isolate: ^2.0.4
Hello @karamatpkid, the flutter_isolate: ^2.0.4 does not support Web, are you using it to fix the Flutter mobile project only? My project is a Flutter Web. Will you please share your code use flutter_isolate in flutter_image_compress for my reference, thanks.
Hi @davidCcD , yes you are right .flutter_isolate: ^2.0.4 does not support Web, i worked on Flutter mobile project only.
Hi @davidCcD . Did you solve it?
@Coin-ai Not yet.
Same issue as flutter_isolate
does not work on macOS