fluttercandies / flutter_image_compress

flutter image compress
MIT License
633 stars 214 forks source link

in Isolate, i #235

Open karamatpkid opened 1 year ago

karamatpkid commented 1 year ago

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>
karamatpkid commented 1 year ago

i have resolved using other FlutterIsolate package, now this package works perfectly fine.

Zazo032 commented 1 year ago

Hey @karamatpkid, what did you do to fix the issue with compressing on isolates?

karamatpkid commented 1 year ago

I were using Isolate.spawn . now I am compressing image using flutter_isolate: ^2.0.4

davidCcD commented 1 year ago

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.

karamatpkid commented 1 year ago

Hi @davidCcD , yes you are right .flutter_isolate: ^2.0.4 does not support Web, i worked on Flutter mobile project only.

Coin-ai commented 1 year ago

Hi @davidCcD . Did you solve it?

davidCcD commented 1 year ago

@Coin-ai Not yet.

themobilecoder commented 10 months ago

Same issue as flutter_isolate does not work on macOS