Fix Flutter apps not running at max available frame rate on some devices

April 27, 2024

What's going on?

I've been using a Nothing Phone 2 until one day I realized some apps are not running at 120fps. I thought it was an issue on Flutter, did some searching and found out this Github issue. However the fix requires usage of a package and this is what the package mentioned:

A Flutter plugin to set display mode in Android. This is useful to enable high refresh rate in devices with discrete framerates like 60Hz, 90Hz etc. This library is ineffective on devices with LTPO panels and iOS devices with ProMotion.

The Nothing Phone 2 is using LTPO panel so it won't work.

How to fix?

In MainActivity.kt, override onFlutterSurfaceViewCreated and set window.attributes with preferredRefreshRate of 120F:

1 2 3 4 5 6 7 8 9 10 import io.flutter.embedding.android.FlutterActivity import io.flutter.embedding.android.FlutterSurfaceView class MainActivity: FlutterActivity() { override fun onFlutterSurfaceViewCreated(flutterSurfaceView: FlutterSurfaceView) { super.onFlutterSurfaceViewCreated(flutterSurfaceView) window.attributes = window.attributes.also { it.preferredRefreshRate = 120F } } }

Note

The above solution is only tested on Nothing Phone 2. It might work for other Android devices that have the same issue but you need to test it out yourselves.

Hope it helps :)

© 2024 Alan Chan.