---
title: "Discussion on \"Flutter: Unblocking UI thread with Isolates compute function\" | Hashnode"
description: "Discussion on \"Flutter: Unblocking UI thread with Isolates compute function\". In this post I will show you, how to use compute function from the Flutter framework  to push CPU-heavy computation from main thread (which does the UI stuff) to another thread. This will unlock the main thread and your application will be responsive..."
url: "https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Flutter: Unblocking UI thread with Isolates compute function](https://gladimdim.org/flutter-unblocking-ui-thread-with-isolates-compute-function?utm_source=hashnode&utm_medium=feed)

In this post I will show you, how to use compute function from the Flutter framework to push CPU-heavy computation from main thread (which does the UI stuff) to another thread. This will unlock the main thread and your application will be responsive...

Sep 3, 2019 · gladimdim.org  
Updated Jun 8, 2020  
Read the article

-   [#asynchronous](https://hashnode.com/tag/asynchronous)
-   [#flutter-cjx3aa7op001jims1kuwl3ekz](https://hashnode.com/tag/flutter-cjx3aa7op001jims1kuwl3ekz)
-   [#advanced](https://hashnode.com/tag/advanced)

## Written by

[Dmytro Gladkyi](https://hashnode.com/@dmytrogladkyi)

@dmytrogladkyi · Kyiv, Ukraine

  
[View profile](https://hashnode.com/@dmytrogladkyi)

Unity & Web Developer

## Responses 1

Markdown supported · ⌘↵ to post

[Fernando Lam](https://hashnode.com/@fenchai)

[Oct 5, 2020](https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1/comment/5f7b1685a4bdec5ef0a751f2)

I do something different which is exporting the created pdf into png files which takes a heavy toll on the main thread. Do you know if there is a way to compute the below?

```
if (!isPdf) {
  int pageIndex = 1;

  await for (var page in Printing.raster(pdf.save(), dpi: 300)) {
    final image = await page.toPng();

    final String pageQty =
        (pagesToPrint > 1) ? '$pageIndex-$pagesToPrint' : '1-1';

    file = File("${output.path}/$fileName--$pageQty.png");

    await file.writeAsBytes(image);

    imageList.add(file);

    pageIndex++;
  }
} else {
  file = File("${output.path}/$fileName.pdf");

  await file.writeAsBytes(pdf.save());

  imageList.add(file);
}
```

[Dmytro Gladkyi](https://hashnode.com/@dmytrogladkyi)

[Oct 5, 2020](https://hashnode.com/posts/flutter-unblocking-ui-thread-with-isolates-compute-function/5d6e4c943e3f2adc43b93fc1/comment/5f7b1685a4bdec5ef0a751f2#reply-5f7b3ce7e93896601dd28ba7)

I think you need to check what is going on in pdf.toPng method call. Maybe it is possible to move that code inside compute function :)
