diff --git a/lib/main.dart b/lib/main.dart index 869745b..7e2b6e2 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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'; @@ -111,10 +112,28 @@ class PageBaseState extends State { @override void initState() { + setOptimalDisplayMode(); if (!_isCheckingForUpdate) _checkForUpdate(); // ik that it's not necessary super.initState(); } + Future setOptimalDisplayMode() async { + final List supported = await FlutterDisplayMode.supported; + final DisplayMode active = await FlutterDisplayMode.active; + + final List 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; diff --git a/pubspec.lock b/pubspec.lock index f1e1a57..b947da1 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -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 diff --git a/pubspec.yaml b/pubspec.yaml index 27c9665..61aa3d9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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