Flutter 120fps issue

Viewed 3718

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.

3 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.

Please try this, you can use media query for sizing your widget.

MediaQuery.of(context).size
Related