Flutter heavy platform code causes UI lag
pskink's suggestion of using a HandlerThread
did the trick! I now can scroll smoothly even without preloading.
Lucas
Updated on November 28, 2022Comments
-
Lucas over 1 year
I'm using
MethodChannel.invoke
to call some platform code to return app icons asUint8List
s. This happens for a list of all the apps on a device (can be quite a lot), displayed asFutureBuilder
s in aListView.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?