Lucas
Lucas

Reputation: 2832

Flutter heavy platform code causes UI lag

I'm using MethodChannel.invoke to call some platform code to return app icons as Uint8Lists. This happens for a list of all the apps on a device (can be quite a lot), displayed as FutureBuilders in a ListView.builder.

This caused a lot of stutter when scrolling quickly in the ListView, so I changed it so that all the app icons are preloaded before displaying the ListView. This fixes the scrolling, but the UI is very janky while the icons are loading.

I believe the problem may be the same as this issue, and I shouldn't be loading the icons on the UI thread the way it is now. However, looking at the docs for compute, I don't think I will be able to use it to call platform code.

Is there another way I can avoid the UI lag?

Upvotes: 3

Views: 1194

Answers (1)

Lucas
Lucas

Reputation: 2832

pskink's suggestion of using a HandlerThread did the trick! I now can scroll smoothly even without preloading.

Upvotes: 2

Related Questions