flutter_avif icon indicating copy to clipboard operation
flutter_avif copied to clipboard

Does not work in isolate

Open NattyPluz opened this issue 3 years ago • 3 comments

I was trying to encode an image to AVIF in isolate using compute but it shows the following error:

Unhandled Exception: LateInitializationError: Field 'api' has not been initialized. FlutterAvifPlatform.api (package:flutter_avif_platform_interface/flutter_avif_platform_interface.dart) encodeAvif (package:flutter_avif/src/avif_encoder.dart:16:53)

NattyPluz avatar Nov 18 '22 10:11 NattyPluz

Hi, error you are getting can be solved by calling DartPluginRegistrant.ensureInitialized() before using the plugin. But after that you will encounter other errors. The real issue here is that encodeAvif function uses dart:ui package to read images as rgba and dart:ui does not work in isolates. So you cannot use encodeAvif in an isolate.

yekeskin avatar Nov 18 '22 15:11 yekeskin

use flutter_isolate, you can use all packages in isolate.

ozexpert avatar Feb 08 '23 01:02 ozexpert