flutter_image_compress icon indicating copy to clipboard operation
flutter_image_compress copied to clipboard

in Isolate, i

Open karamatpkid opened this issue 2 years ago • 8 comments

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 avatar Feb 07 '23 12:02 karamatpkid

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

karamatpkid avatar Feb 10 '23 13:02 karamatpkid

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

Zazo032 avatar Mar 23 '23 11:03 Zazo032

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

karamatpkid avatar Mar 23 '23 17:03 karamatpkid

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.

davidCcD avatar Jun 09 '23 15:06 davidCcD

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

karamatpkid avatar Jun 10 '23 07:06 karamatpkid

Hi @davidCcD . Did you solve it?

Coin-ai avatar Jun 23 '23 06:06 Coin-ai

@Coin-ai Not yet.

davidCcD avatar Jun 23 '23 07:06 davidCcD

Same issue as flutter_isolate does not work on macOS

themobilecoder avatar Nov 01 '23 10:11 themobilecoder