Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter 120fps issue

scenario: have an application in flutter with a hard-coded list of 20 cards after a release build of this on my 120 fps devices it still feels like 60 fps how to fix it while the native android counterpart has a smooth render at 120 fps.

have tries the above scenario will the scrolling based widget both builder-based and normal ones.

Is it a flaw in flutter that it doesn't render at 120 fps.

like image 866
Snivio Avatar asked Aug 23 '26 11:08

Snivio


1 Answers

On Android phones with 120hz display by default is chosen the wrong display mode (e.g. 60hz instead 120hz). This can easily be corrected, then performance on phones like Oneplus 8T or Galaxy S20+ is great.

  1. Import flutter_displaymode library:
flutter_displaymode: ^0.3.0-nullsafety.0
  1. Add this to your root widget (stateful):
class _YourAppState extends State<YourApp> {

  @override
  void initState() {
    setOptimalDisplayMode();
    super.initState();
  }

  Future<void> setOptimalDisplayMode() async {
    final List<DisplayMode> supported = await FlutterDisplayMode.supported;
    final DisplayMode active = await FlutterDisplayMode.active;

    final List<DisplayMode> sameResolution = supported.where(
            (DisplayMode m) => m.width == active.width
                && m.height == active.height).toList()..sort(
            (DisplayMode a, DisplayMode b) =>
                b.refreshRate.compareTo(a.refreshRate));

    final DisplayMode mostOptimalMode = sameResolution.isNotEmpty
        ? sameResolution.first
        : active;

    /// This setting is per session.
    /// Please ensure this was placed with `initState` of your root widget.
    await FlutterDisplayMode.setPreferredMode(mostOptimalMode);
  }
}

Note, that right now there are no 120hz iPhones, so there is no need to execute them.

like image 78
Timo Bähr Avatar answered Aug 24 '26 23:08

Timo Bähr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!