搜尋套件、儲存庫與 APP 分類

套件詳情v0.7.0

flutter_displaymode

一個用於在 Android 平台上設定顯示模式(解析度、更新率)的 Flutter 外掛程式。可在支援的裝置上啟用高更新率。

Android
近 30 天下載
13萬
喜歡數
220
Pub 分數
160

安裝套件

flutter pub add flutter_displaymode

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

flutter_displaymode 是一個 Flutter 插件,可讓開發者透過程式設計方式在 Android 設備上設定顯示模式(例如解析度和更新率)。它特別適用於透過啟用支援硬體的高更新率來優化效能與視覺品質。此插件提供對 Android 顯示設定的直接存取,讓應用程式能動態適應裝置功能。由於此功能為平台特定,因此不支援 iOS。

適用情境

  • 在高刷新率螢幕上優化應用程式效能
  • 為遊戲應用啟用90Hz或120Hz更新率
  • 調整顯示解析度以獲得更好的視覺清晰度
  • 在動畫密集型應用中提升使用者介面的流暢度
  • 測試在不同螢幕設定下的顯示行為

主要特色

  • 設定Android顯示解析度和更新率
  • 支援在相容裝置上使用高刷新率模式
  • 提供用於設定顯示模式的簡單 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.

所屬分類

原始碼儲存庫

使用此套件的專案