Giter Site home page Giter Site logo

rewtio / flutter_displaymode Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajinasokan/flutter_displaymode

0.0 0.0 0.0 120 KB

A Flutter plugin to set display mode in Android

License: MIT License

Ruby 18.01% Objective-C 3.15% Java 28.45% Dart 46.36% Swift 4.03%

flutter_displaymode's Introduction

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.

flutter_displaymode's People

Contributors

ajinasokan avatar alexv525 avatar vbuberen avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.