Flutter heavy platform code causes UI lag

914

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

Share:
914
Lucas
Author by

Lucas

Updated on November 28, 2022

Comments

  • Lucas
    Lucas over 1 year

    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?