• Stars
    star
    179
  • Rank 214,039 (Top 5 %)
  • Language
    Dart
  • License
    MIT License
  • Created over 4 years ago
  • Updated almost 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Flutter plugin to set display mode in Android

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.

More Repositories

1

autopilot

A test driver for Flutter to do QA testing without sharing app source code.
Dart
105
star
2

flutter_fgbg

Flutter plugin to detect when app(not Flutter container) goes to background or foreground
Dart
79
star
3

apkc

apkc is a bare-bones Android app build system that lets you build simple native Android apps without entire Android IDE
Go
69
star
4

flutter_curl

Flutter plugin to use libcurl for HTTP calls
Dart
51
star
5

recharge

Recharge is a simple library to hot reload your Dart code on file changes
Dart
48
star
6

store_keeper

StoreKeeper is an easy and flexible state management system for Flutter apps
Dart
34
star
7

dartgen

An inline generator collection for Dart & Flutter projects
Dart
32
star
8

ditto

A simple dictionary app built using Flutter. Powers Olam and Alar mobile apps.
Dart
28
star
9

tag

Digital version of the classic tag game. Made for #FlutterCreate contest.
Dart
21
star
10

flutter_local_auth

local_auth, but with support for devices that doesn't advertise the feature flag PackageManager.FEATURE_FINGERPRINT
Dart
20
star
11

artham

A lightweight English to Malayalam dictionary app for Android
Java
19
star
12

overlay_webview

A Flutter WebView plugin that shows as an overlay to Flutter app without performance overhead.
Dart
17
star
13

fast

CLI for fast.com written in Go
Go
13
star
14

smallest-android-app-from-scratch

Build the smallest 6 KB Android app from scratch
Java
11
star
15

xvm

A simple directory scoped version manager for commands
Go
8
star
16

flutter_curl_binary

Dart script to build curl for Android, iOS and macOS
Dart
5
star
17

logd_client

Logd client for Flutter/Dart
Dart
5
star
18

flutter_raw_assets

A Flutter plugin to read large assets in chunks of bytes
Dart
5
star
19

react-native-shadowview

Java
4
star
20

wifi_access

A Flutter plugin to get WiFi related functions.
Ruby
2
star
21

no-node-preact-spa

HTML
1
star
22

cgo-static-minimal

Minimal example to use CGO with a static linked C lib
Makefile
1
star
23

force_landscape

A plugin to force landscape mode in Flutter in iOS 16.0
Dart
1
star