搜索插件、代码仓与 APP 分类

插件详情v0.7.0

flutter_displaymode

一个用于在 Android 平台上设置显示模式(分辨率、刷新率)的 Flutter 插件。可在支持的设备上启用高刷新率。

Android
近 30 天下载
12.5万
喜欢数
220
Pub 分数
160

安装插件

flutter pub add flutter_displaymode

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

flutter_displaymode 是一个 Flutter 插件,允许开发者在 Android 设备上通过编程方式设置显示模式(如分辨率和刷新率)。它特别适用于通过启用支持硬件的高刷新率来优化性能和视觉质量。该插件提供了对 Android 显示设置的直接访问,使应用程序能够动态适应设备功能。由于该功能是平台特定的,因此不支持 iOS。

适合场景

  • 在高刷新率屏幕上优化应用性能
  • 为游戏应用启用90Hz或120Hz刷新率
  • 调整显示分辨率以获得更好的视觉清晰度
  • 在动画密集型应用中提升用户界面的流畅度
  • 测试在不同屏幕配置下的显示行为

主要特点

  • 设置安卓显示分辨率和刷新率
  • 支持在兼容设备上使用高刷新率模式
  • 提供用于设置显示模式的简单 API
  • 特定于 Android
  • 不需要 root 权限

适合对象

  • Android游戏开发者
  • 需要高性能UI渲染的应用程序
  • 面向高端安卓设备的开发者
  • 专注于视觉保真度的应用程序
  • 工具测试显示功能

使用建议

  • 仅适用于安卓设备
  • 需要设备支持动态显示模式更改
  • 可能无法在所有Android版本上正常运行
  • 更改可能被系统或用户撤销
  • 仅限特定硬件功能

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Display Mode

pub package

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.

This library should be used as a temporary fix to #35162 until this API gets added to Flutter engine itself.

Getting Started

Add library to pubspec then and rebuild your app:

flutter pub add flutter_displaymode
Set to highest/lowest framerate

Use helper functions FlutterDisplayMode.setHighRefreshRate or FlutterDisplayMode.setLowRefreshRate to switch to highest or lowest refresh rate maintaining current resolution.

// current: #1 1440x3120 @ 60Hz
// new: #2 1440x3120 @ 90Hz
await FlutterDisplayMode.setHighRefreshRate();

// current: #2 1440x3120 @ 90Hz
// new: #1 1440x3120 @ 60Hz
await FlutterDisplayMode.setLowRefreshRate();
Get supported modes

FlutterDisplayMode.supported returns all the modes that can be set as the preferred mode. This always returns DisplayMode.auto as one of the modes.

import 'package:flutter_displaymode/flutter_displaymode.dart';

try {
  modes = await FlutterDisplayMode.supported;
  modes.forEach(print);

  /// On OnePlus 7 Pro:
  /// #0 0x0 @0Hz // Automatic
  /// #1 1080x2340 @ 60Hz
  /// #2 1080x2340 @ 90Hz
  /// #3 1440x3120 @ 90Hz
  /// #4 1440x3120 @ 60Hz

  /// On OnePlus 8 Pro:
  /// #0 0x0 @0Hz // Automatic
  /// #1 1080x2376 @ 60Hz
  /// #2 1440x3168 @ 120Hz
  /// #3 1440x3168 @ 60Hz
  /// #4 1080x2376 @ 120Hz
} on PlatformException catch (e) {
  /// e.code =>
  /// noAPI - No API support. Only Marshmallow and above.
  /// noActivity - Activity is not available. Probably app is in background
}
Get active mode

FlutterDisplayMode.active fetches the currently active mode. This is not always the preferred mode set by FlutterDisplayMode.setPreferredMode. It can be altered by the system based on the display settings.

final DisplayMode m = await FlutterDisplayMode.active;
Set preferred mode

FlutterDisplayMode.setPreferredMode changes the preferred mode. It is upto the system to use this mode. Sometimes system can choose not switch to this based on internal heuristics. Check FlutterDisplayMode.active to see if it actually switches.

/// This setting is per session. 
/// Please ensure this was placed with `initState` of your root widget.
await FlutterDisplayMode.setPreferredMode(modes[1]);
Get preferred mode

FlutterDisplayMode.preferred returns the currently preferred mode. If not manually set with FlutterDisplayMode.setPreferredMode then it will be DisplayMode.auto.

final DisplayMode m = await FlutterDisplayMode.preferred;

You can check out a complete example here.

所属分类

源码仓库

使用此插件的项目