Why does this function block flutter's ui? Why does this function block flutter's ui? dart dart

Why does this function block flutter's ui?


You can try making your function async but there are chances that your UI might be stuck.

How it works is there is an eventloop which loops through eventqueue and microtask queue to check if something is there to process. If there is it will process it while the application is waiting. This can cause the UI to not respond when some function hasn't returned from completion.

In your scenario, as it involves compression and encoding, you should use 3rd party plugin or use isolates to load off the task from main isolate.


declare your function with the async keyword.

Future<List<int>> _compressFiles(List<Uint8List> data) async{}