Baseflow / flutter_cache_manager

Generic cache manager for flutter
https://baseflow.com
MIT License
740 stars 429 forks source link

How to use Cache Manager in a compute() method? #277

Closed DonAlex1897 closed 3 years ago

DonAlex1897 commented 3 years ago

When I am trying to use DefaultCacheManager().getSingleFile(fileAddress), this error occurs:

E/flutter (32196): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: Exception: ServicesBinding.defaultBinaryMessenger was accessed before the binding was initialized.

I tried adding WidgetsFlutterBinding.ensureInitialized() to the first line of the main method, as flutter proposed. But it did not resolve my problem.

renefloor commented 3 years ago

You can't. At least the default one uses sqflite which uses methodchannels and these are only supported on the main isolate. See: https://github.com/flutter/flutter/issues/16846#issuecomment-383752606

What are you trying to do in the compute method?

DonAlex1897 commented 3 years ago

I need to download a list of audio files from the server. When the first file is downloaded, it should be played. So I have to download the other audio files of the list in the background. Downloading process of other audio files is being done in the compute method.

renefloor commented 3 years ago

I/O and http calls are always done asynchronously on their own isolate. So you shouldn't need compute for what you are trying to do. Did you try without compute? Could you give me an example that's not working?

DonAlex1897 commented 3 years ago

Yes. You are right. I just realized that I had used the compute method because of a "synchronous decryption" method. Now that I am using my own built encryption method, I do not need the compute anymore. Thanks for your attention.

eldarkk commented 1 year ago

Do we have another cache managers (or settings) which are accessible from other isolates.