Skip to content

Commit

Permalink
Add support for higher refresh rates (120Hz)
Browse files Browse the repository at this point in the history
  • Loading branch information
vyPal committed Feb 8, 2024
1 parent 688cf99 commit 2b8e0b8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
19 changes: 19 additions & 0 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:firebase_analytics/firebase_analytics.dart';
import 'package:firebase_remote_config/firebase_remote_config.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_displaymode/flutter_displaymode.dart';
import 'package:flutter_session_manager/flutter_session_manager.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:restart_app/restart_app.dart';
Expand Down Expand Up @@ -111,10 +112,28 @@ class PageBaseState extends State<PageBase> {

@override
void initState() {
setOptimalDisplayMode();
if (!_isCheckingForUpdate) _checkForUpdate(); // ik that it's not necessary
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;

await FlutterDisplayMode.setPreferredMode(mostOptimalMode);
}

@override
void setState(VoidCallback fn) {
if (!mounted) return;
Expand Down
8 changes: 8 additions & 0 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.4.2"
flutter_displaymode:
dependency: "direct main"
description:
name: flutter_displaymode
sha256: "42c5e9abd13d28ed74f701b60529d7f8416947e58256e6659c5550db719c57ef"
url: "https://pub.dev"
source: hosted
version: "0.6.0"
flutter_driver:
dependency: transitive
description: flutter
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ dependencies:
flutter_linkify: ^6.0.0
dynamic_color: ^1.4.0
firebase_remote_config: ^4.2.6
flutter_displaymode: ^0.6.0
dev_dependencies:
integration_test:
sdk: flutter
Expand Down

0 comments on commit 2b8e0b8

Please sign in to comment.