Code Monkey home page Code Monkey logo

screen_brightness's People

Contributors

aaassseee avatar cnting avatar deckerst avatar ggirotto avatar jackliu-gulu avatar johnsmith0922 avatar niku avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

screen_brightness's Issues

[q] System brigthness slider is disabled because controlled by the running app

Description

I got this message if I try to adjust the brightness manually from the system slider:

Can't adjust brihtness in the quick panel right now because it's being controlled by the currently running app.

Screenshot_20220325-115449

I use this plugin to set the brighness at a low value when entering my sleep mode screen. This is the code:

import 'package:async/async.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:screen_brightness/screen_brightness.dart';

import '../screens/sleep_mode/sleep_mode.screen.dart';

const _sleepModeInactivityTimeout = Duration(seconds: 5);
const _sleepModeTransitionDuration = Duration(seconds: 1);
const _lowScreenBrightnessValue = 0.2;

class SleepModeListener extends StatefulWidget {
  const SleepModeListener({Key? key, required this.child}) : super(key: key);

  final Widget child;

  @override
  State<SleepModeListener> createState() => _SleepModeListenerState();
}

class _SleepModeListenerState extends State<SleepModeListener> {
  late RestartableTimer _sleepTimer;

  @override
  void initState() {
    super.initState();
    _sleepTimer =
        RestartableTimer(_sleepModeInactivityTimeout, _setToSleepMode);
  }

  @override
  Widget build(BuildContext context) => Listener(
        onPointerDown: (event) {
          _sleepTimer.reset();
        },
        child: widget.child,
      );

  void _setToSleepMode() async {
    _sleepTimer.cancel();

    await _setScreenBrightnessDown();

    Get.dialog(
      const SleepMode(),
      transitionDuration: _sleepModeTransitionDuration,
      useSafeArea: false,
    ).then(
      (value) {
        _resetScreenBrightness();
        _sleepTimer.reset();
      },
    );
  }

  Future<void> _setScreenBrightnessDown() async {
    ScreenBrightness().setScreenBrightness(_lowScreenBrightnessValue);
  }

  Future<void> _resetScreenBrightness() =>
      ScreenBrightness().resetScreenBrightness();
}

Step to reproduce

  1. just call ScreenBrightness().setScreenBrightness()
  2. Then try to move the system slider

Platform

Found on an Android physical device with Android 11, emulator works fine.

[feat] Ability to query/set multiple display brightness

Description (What is the problem)

On a system with multiple displays (macOS / Windows) it would be beneficial to be able to set different brightness settings for each display. Especially in the case that the displays have different brightness capabilities.

Solution suggestion

Allow querying of list of display devices.
Allow reading or setting brightness for each display.

[bug] abort() has been callled

Description (bug summary)

adding the plugin to any flutter project will cause a crash on the windows platform
you can find more details in this issue link

Step to reproduce (how to reproduce the bug)

Simply add screen_brightness: ^0.2.2 to any flutter windows project and the app will crash immediately

Platform (Windows)

[q] HOW TO SOLVE THIS ERROR?

Description (What are you difficulties)

E/flutter (18328): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: MissingPluginException(No implementation found for method setScreenBrightness on channel github.com/aaassseee/screen_brightness)

[bug] Importing `screen_brightness` package messes up auto brightness for the app.

Description (bug summary)

Recently I've added screen_brightness to our app to change the brightness of one screen.
Since then, people started mentioning that the app gets very dark. At first, I thought it was just them not understanding the auto-brightness of the phone but lately, I've started to notice it myself. The app sets the brightness of the screen to a much lower setting than it normally is. (and also lower in comparison to other apps)

Step to reproduce (how to reproduce the bug)

  1. Add screen_brightness in pubspec.yaml
  2. Open the app
  3. Set brightness to max
  4. Lock the screen
  5. Wait for the brightness to auto adjust
  6. Unlock the screen
  7. Notice much lower brightness than before

Here's the recording of what it looks like:

WhatsApp.Video.2024-02-20.at.13.51.00.mp4

And here's without the package.

WhatsApp.Video.2024-02-20.at.13.55.16.mp4

There is no package code running, it's just importing the package in pubspec.

Platform (Android/iOS/macOS/Windows)

iOS, haven't seen it on Android yet.

Thank you for this package! You're doing a great job! πŸ’™

[bug] System brightness doesn't update when app is focused

Description (bug summary)

I was playing around with screen_brightness to see if I can have real-time data on system brightness. My use case is to have app change to light/dark theme based on system's brightness (for instance, have dark mode activated automatically when system brightness dips below 0.30 β€” and activate light theme when the opposite is true).
It works, for so long as the app is not in the foreground/not focused β€” the moment the app window is focused, it doesn't update anymore (gets stuck with the last result) β€” put app in background, and now works fine again.

Tried both ScreenBrightness().current and ScreenBrightness().system to no avail.

The following is the code I played with:

FutureBuilder<double>(
  future: ScreenBrightness().current,
  //future: ScreenBrightness().system,
  builder: (context, snapshot) {
    double currentBrightness = 0;
    if (snapshot.hasData) {
      currentBrightness = snapshot.data!;
    }

    return StreamBuilder<double>(
      stream: ScreenBrightness()
          .onCurrentBrightnessChanged,
      builder: (context, snapshot) {
        double changedBrightness =
            currentBrightness;
        if (snapshot.hasData) {
          changedBrightness = snapshot.data!;
        }

        return Text('Current brightness: $changedBrightness');
      },
    );
  },
),

Also, with the following:

double _brightness = 0;

@override
void initState() {
  super.initState();
  _getBrightness();
  _onCurrentBrightnessChanged();
}

Future<void> _getBrightness() async {
  final brightness = await ScreenBrightness().system;
  setState(() {
    _brightness = brightness;
  });
}

void _onCurrentBrightnessChanged() {
  ScreenBrightness().onCurrentBrightnessChanged.listen((brightness) {
    setState(() {
      _brightness = brightness;
    });
    //print(_brightness);
  });
}

but the result is the same.

Step to reproduce (how to reproduce the bug)

  1. Run example/lib/main.dart
  2. While the app is focused, change system brightness (doesn't work in my case)
  3. While the app is not focused, change system brightness (works great)

Platform (only tested on iOS and macOS)

The above steps apply to macOS (testing hardware: MBP 13' 2017, using macOS Ventura 13.0).

For iOS (testing hardware: iPhone X, using iOS 16.5), I was turning room lights on and off β€” and it was not updating, even though the screen's brightness was changing. Sidenote: While the app is running, if we open the control center and change system's brightness manually β€” it works, but it doesn't count because the app is losing focus this way. And the desired outcome is to follow system's brightness in real-time, while using the app.

[bug] Xcode compile error

Description (bug summary)

(lldb) dyld[14557]: Library not loaded: @rpath/libswiftCore.dylib

Step to reproduce (how to reproduce the bug)

  1. pubspec.yaml add screen_brightness: ^0.2.2
  2. project run to device (I haven't written the code yet)
  3. add the β€œusr/lib/swift” path to the Runpath Search Paths. Under debugging, the problem can be solved, but ad hoc or flash back

Platform (Android/iOS/macOS/Windows)

iOS

[bug] Crash at startup only with iOS 11

Description (bug summary)

My Flutter app crashes immediately on iOS 11 if I import the plugin in pubspec.yaml, even if I never actually use it.

Step to reproduce (how to reproduce the bug)

  1. Add screen_brightness: ^0.2.2 as a dependency in pubspec.yaml.
  2. Make an IPA build.
  3. Install on any device with iOS 11.
  4. Start the app.
  5. The app crashes immediately.

Platform (Android/iOS/macOS/Windows)

I tested the bug on iPhone 8 using iOS 11.3. The same device model with iOS 12.1 works properly.
I can also replicate the bug on iPhone 6S Plus with iOS 11.4.

(I know it's an old OS, but our app is used by a large demographics and we'd like to support older devices too.)

[bug] On iOS, screen brightness will always restore to initial brightness when app pauses

The plugin should not alter screen brightness unless explicitly instructed to do so.

However, the plugin has a bug in lifecycle handling that causes the app to always reset the brightness to the initial state when it is about to be paused, even when no method of the plugin has ever been called.

Reproduce:
0. Create a minimal project and add this as a plugin in Pubspec.yaml, don’t modify other code. Compile and run

  1. Quit app
  2. Set Brightness to minimum via Control Center
  3. Launch app
  4. Set Brightness to maximum via Control Center
  5. Return to Home Screen
    -> brightness changes to minimum, which is unexpected

EDIT: Also, the Reset Brightness function always resets the brightness to the state when the application was initially launched. However, an iOS app might stay in background for a long time and the brightness has probably changed since then. We might want to update originalBrightness when calling setBrightness() or when the application resumes from background.

[feat] Add iOS privacy manifests

Description (What is the problem)

By Apple's Privacy manifest guidelines,
some action will be required such as adding an empty privacy manifests file even if you are not collecting anything.

Apple's document: https://developer.apple.com/documentation/bundleresources/privacy_manifest_files
See flutter/flutter#131940 for more context.

Solution suggestion

Add privacy manifests file (PrivacyInfo.xcprivacy) according to library privacy usage.

The following is an example of an empty privacy manifests file if this library is not collecting anything.
device_info_plus/ios/PrivacyInfo.xcprivacy

[feat] Duration of brightness change on Android

Description (What is the problem)

There is no way to control how fast the brightness changes on Android.

Solution suggestion

A 'duration' property that lets you set the duration with the Duration class. Is this possible?

[bug][Windows] Invalid pointer read fail fast unexpected heap exception

Description (bug summary)

I'm seeing a lot of crashes reported by Microsoft dev console. The name of the error is the following:
invalid_pointer_read_fail_fast_unexpected_heap_exception_c0000409_screen_brightness_windows_plugin.dll!unknown
Here is the stack trace they are providing :
Apps-and-Games-Health-details-Stack-prevalance-Stack-Trace (1).csv

Step to reproduce (how to reproduce the bug)

Honestly, I don't know what the users are doing to get the error.

Platform (Android/iOS/macOS/Windows)

Windows

[bug] get current brightness gets 2.8

I/flutter (23765): RangeError: Invalid value: Not in inclusive range 0..1: 2.8392157554626465
I/flutter (23765): Failed to get current brightness

this happened when testing on pocophone f1 (and has android 10- Miui 12.0.3)

[bug] The getter 'isAnimate' isn't define on 1.0.1

Version: 1.0.1

How to reproduce:

  1. add screen_brightness: ^1.0.1
  2. (optional) flutter pub cache clean
  3. (optional) flutter pub clean
  4. flutter pub get
  5. run

The error:

..../AppData/Local/Pub/Cache/hosted/pub.dev/screen_brightness-1.0.1/lib/screen_brightness.dart:151:43: Error: The getter 'isAnimate' isn't defined for the class 'ScreenBrightnessPlatform'.
 - 'ScreenBrightnessPlatform' is from 'package:screen_brightness_platform_interface/screen_brightness_platform_interface.dart' ('..../AppData/Local/Pub/Cache/hosted/pub.dev/screen_brightness_platform_interface-1.0.0/lib/screen_brightness_platform_interface.dart').
Try correcting the name to the name of an existing getter, or defining a getter or field named 'isAnimate'.
  Future<bool> get isAnimate => _platform.isAnimate;
                                          ^^^^^^^^^
.../AppData/Local/Pub/Cache/hosted/pub.dev/screen_brightness-1.0.1/lib/screen_brightness.dart:160:56: Error: The method 'setAnimate' isn't defined for the class 'ScreenBrightnessPlatform'.
 - 'ScreenBrightnessPlatform' is from 'package:screen_brightness_platform_interface/screen_brightness_platform_interface.dart' ('.../AppData/Local/Pub/Cache/hosted/pub.dev/screen_brightness_platform_interface-1.0.0/lib/screen_brightness_platform_interface.dart').
Try correcting the name to the name of an existing method, or defining a method named 'setAnimate'.
  Future<void> setAnimate(bool isAnimate) => _platform.setAnimate(isAnimate);
                                                       ^^^^^^^^^^

[q] Can Linux also be supported?

Hi @aaassseee,
first of all thank you for your contribution!

I wanted to ask as the title suggests, if it is possible to add compatibility for Linux as well.

Thanks in advance and have a nice day!

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.