Giter Club home page Giter Club logo

flutter_screen's Introduction

Screen

pub package A Flutter plugin to manage the device's screen on Android and iOS.

Usage

To use this plugin, add screen as a dependency in your pubspec.yaml file.

Make sure you add the following permissions to your Android Manifest

<uses-permission android:name="android.permission.WAKE_LOCK" />

Example

// Import package
import 'package:screen/screen.dart';

// Get the current brightness:
double brightness = await Screen.brightness;

// Set the brightness:
Screen.setBrightness(0.5);

// Check if the screen is kept on:
bool isKeptOn = await Screen.isKeptOn;

// Prevent screen from going into sleep mode:
Screen.keepOn(true);

flutter_screen's People

Contributors

clovisnicolas avatar ened avatar matejm 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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  avatar  avatar  avatar  avatar

flutter_screen's Issues

When I setState, MissingPluginException

I was ,

  1. in pubspec.yaml
    dependencies:
    flutter:
    sdk: flutter
    screen: ^0.0.5

  2. in androidManifest

  3. copy to Paste in my code.
    https://pub.dev/packages/screen/example

  • code

import 'package:flutter/material.dart';
import 'package:screen/screen.dart';

void main() => runApp(new MyApp());

class MyApp extends StatefulWidget {
@OverRide
_MyAppState createState() => new _MyAppState();
}

class _MyAppState extends State {
bool _isKeptOn = false;
double _brightness = 1.0;

@OverRide
initState() {
super.initState();
initPlatformState();
}

initPlatformState() async {
bool keptOn = await Screen.isKeptOn;
double brightness = await Screen.brightness;
setState(() {
_isKeptOn = keptOn;
_brightness = brightness;
});
}

@OverRide
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(title: new Text('Screen plugin example')),
body: new Center(
child: new Column(children: [
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
new Text("Screen is kept on ? "),
new Checkbox(
value: _isKeptOn,
onChanged: (bool b) {
Screen.keepOn(b);
setState(() {
_isKeptOn = b;
});
})
]),
new Text("Brightness :"),
new Slider(
value: _brightness,
onChanged: (double b) {
setState(() {
_brightness = b;
});
Screen.setBrightness(b);
})
])),
),
);
}
}


Successful hot load.... but,
When I setState, I met the "MissingPluginException"

Error: MissingPluginException(No implementation found for method setBrightness on channel github.com/clovisnicolas/flutter_screen)
at Object.throw_ [as throw] (http://localhost:54117/dart_sdk.js:5334:11)
at MethodChannel._invokeMethod (http://localhost:54117/packages/flutter/src/services/system_channels.dart.lib.js:954:21)
at _invokeMethod.next ()
at http://localhost:54117/dart_sdk.js:39032:33
at _RootZone.runUnary (http://localhost:54117/dart_sdk.js:38889:58)
at _FutureListener.thenAwait.handleValue (http://localhost:54117/dart_sdk.js:33875:29)
at handleValueCallback (http://localhost:54117/dart_sdk.js:34435:49)
at Function._propagateToListeners (http://localhost:54117/dart_sdk.js:34473:17)
at _Future.new.[_completeWithValue] (http://localhost:54117/dart_sdk.js:34315:23)
at async._AsyncCallbackEntry.new.callback (http://localhost:54117/dart_sdk.js:34338:35)
at Object._microtaskLoop (http://localhost:54117/dart_sdk.js:39176:13)
at _startMicrotaskLoop (http://localhost:54117/dart_sdk.js:39182:13)
at http://localhost:54117/dart_sdk.js:34689:9


I used flutter 2.0.1 (stable),
I tried to "flutter clean".

Brightness not changing on Android 9.0 Pie

I implemented your example for setting the brightness (on Android) but it doesn't change anything.
Also getting the brightness with Screen.brightness always returns 0, regardless of what i have defined in my settings.

[√] Flutter (Channel master, v0.10.1-pre.10, on Microsoft Windows [Version 10.0.17134.285], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK 28.0.2)
[√] Android Studio (version 3.2)
[√] VS Code (version 1.28.0)
[√] Connected device (1 available)

Running on Android 9.0 Pie.
Tested on emulator and physical device

UPDATE:
Also tested on another device with Android 7.0, there it does work

Brightness not changing on Android 9.0 Pie?

[ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: MissingPluginException(No implementation found for method setBrightness on channel github.com/clovisnicolas/flutter_screen)
E/flutter (31279): #0 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7)
E/flutter (31279):
E/flutter (31279): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter (31279): #2 Screen.setBrightness (package:screen/screen.dart:9:61)
E/flutter (31279): #3 _MyAppState.build. (package:night_mode/main.dart:59:24)
E/flutter (31279): #4 _SliderState._handleChanged (package:flutter/src/material/slider.dart:542:23)
E/flutter (31279): #5 _RenderSlider._startInteraction (package:flutter/src/material/slider.dart:1253:16)
E/flutter (31279): #6 _RenderSlider._handleDragStart (package:flutter/src/material/slider.dart:1288:54)
E/flutter (31279): #7 DragGestureRecognizer._checkStart. (package:flutter/src/gestures/monodrag.dart:384:52)
E/flutter (31279): #8 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:182:24)
E/flutter (31279): #9 DragGestureRecognizer._checkStart (package:flutter/src/gestures/monodrag.dart:384:7)
E/flutter (31279): #10 DragGestureRecognizer.acceptGesture (package:flutter/src/gestures/monodrag.dart:308:7)
E/flutter (31279): #11 _CombiningGestureArenaMember.acceptGesture (package:flutter/src/gestures/team.dart:41:13)
E/flutter (31279): #12 GestureArenaManager._resolveByDefault (package:flutter/src/gestures/arena.dart:250:25)
E/flutter (31279): #13 GestureArenaManager._tryToResolveArena. (package:flutter/src/gestures/arena.dart:231:31)
E/flutter (31279): #14 _rootRun (dart:async/zone.dart:1182:47)
E/flutter (31279): #15 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (31279): #16 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (31279): #17 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)
E/flutter (31279): #18 _rootRun (dart:async/zone.dart:1190:13)
E/flutter (31279): #19 _CustomZone.run (dart:async/zone.dart:1093:19)
E/flutter (31279): #20 _CustomZone.runGuarded (dart:async/zone.dart:997:7)
E/flutter (31279): #21 _CustomZone.bindCallbackGuarded. (dart:async/zone.dart:1037:23)
E/flutter (31279): #22 _microtaskLoop (dart:async/schedule_microtask.dart:41:21)
E/flutter (31279): #23 _startMicrotaskLoop (dart:async/schedule_microtask.dart:50:5)

Only screen brightening works, not dimming.

I have an issue where the lowest the screen brightness can go is the brightness the user has set on their phone.
I'm doing this :

Screen.setBrightness(0.0);

Setting the brightness to max does work, however.

Screen.setBrightness(1.0);

Running Android 10
Works on iOS

Null safety support

Null safety is stable now in flutter. Any plan to migrate flutter_screen to null safety?

not support sound null safety

Your plugin is very convenient to use, but the current flutter SDK has introduced null safety to optimize the code of project, and I hope that your plugin can make use of null safety to perfect plugin as soon as possible! Greatfully!

Package become [UNIDENTIFIED] on pub

As title mentioned, this package is now unidentified on pub, with error as below

ERR: The current Dart SDK version is 2.0.0-dev.63.0.flutter-4c9689c1d2.
Because screen requires SDK version >=2.0.0 <3.0.0, version solving failed.

FAILURE: Build failed with an exception.

When I run flutter build apk get the following information:

* Where:
Build file 'C:\Users\SILENCE\flutter\.pub-cache\hosted\pub.flutter-io.cn\screen-0.0.5\android\build.gradle' line: 11

* What went wrong:
A problem occurred evaluating root project 'screen'.
> Flutter SDK not found. Define location with flutter.sdk in the local.properties file.

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 2s


The plugin screen could not be built due to the issue above.

flutter doctor

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, v1.12.13+hotfix.9, on Microsoft Windows [Version 10.0.18363.778], locale zh-CN)

[√] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[√] Android Studio (version 3.6)
[√] VS Code (version 1.44.2)
[√] Connected device (1 available)

• No issues found!

Configure project :screen WARNING: The specified Android SDK Build Tools version (25.0.3) .....

Launching lib\main.dart on Android SDK built for x86 in debug mode...
Initializing gradle...
Resolving dependencies...

  • Error running Gradle:
    ProcessException: Process "E:\java\Android\Course\youtube\android\gradlew.bat" exited abnormally:

Configure project :screen
WARNING: The specified Android SDK Build Tools version (25.0.3) is ignored, as it is below the minimum supported version (28.0.3) for Android Gradle Plugin 3.2.1.
Android SDK Build Tools 28.0.3 will be used.
To suppress this warning, remove "buildToolsVersion '25.0.3'" from your build.gradle file, as each version of the Android Gradle Plugin now has a default version of the build tools.
Checking the license for package Android SDK Platform 25 in D:\Android_sdk\licenses
Warning: License for package Android SDK Platform 25 not accepted.

FAILURE: Build failed with an exception.

  • What went wrong:
    A problem occurred configuring project ':screen'.

Failed to install the following Android SDK packages as some licences have not been accepted.
platforms;android-25 Android SDK Platform 25
To build this project, accept the SDK license agreements and install the missing components using the Android Studio SDK Manager.
Alternatively, to transfer the license agreements from one workstation to another, see http://d.android.com/r/studio-ui/export-licenses.html

Using Android SDK: D:\Android_sdk

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 22s
Command: E:\java\Android\Course\youtube\android\gradlew.bat app:properties

Finished with error: Please review your Gradle project setup in the android/ folder.

Port package to Dart 2.0

When building example in Dart 2.0, I get following error:

I/FlutterActivityDelegate(17819): onResume setting current activity to this
E/flutter (17819): [ERROR:topaz/lib/tonic/logging/dart_error.cc(16)] Unhandled exception:
E/flutter (17819): type 'Future<dynamic>' is not a subtype of type 'Future<bool>' where
E/flutter (17819):   Future is from dart:async
E/flutter (17819):   Future is from dart:async
E/flutter (17819):   bool is from dart:core
E/flutter (17819): 
E/flutter (17819): #0      Screen.isKeptOn (package:screen/screen.dart:10:48)
E/flutter (17819): #1      _MyAppState.initPlatformState (file:///home/matejm/Desktop/flutter_screen/example/lib/main.dart:22:32)
E/flutter (17819): <asynchronous suspension>
E/flutter (17819): #2      _MyAppState.initState (file:///home/matejm/Desktop/flutter_screen/example/lib/main.dart:18:5)
E/flutter (17819): #3      StatefulElement._firstBuild (package:flutter/src/widgets/framework.dart:3743:58)
E/flutter (17819): #4      ComponentElement.mount (package:flutter/src/widgets/framework.dart:3609:5)
E/flutter (17819): #5      Element.inflateWidget (package:flutter/src/widgets/framework.dart:2899:14)
E/flutter (17819): #6      Element.updateChild (package:flutter/src/widgets/framework.dart:2702:12)
E/flutter (17819): #7      RenderObjectToWidgetElement._rebuild (package:flutter/src/widgets/binding.dart:857:16)
E/flutter (17819): #8      RenderObjectToWidgetElement.mount (package:flutter/src/widgets/binding.dart:828:5)
E/flutter (17819): #9      RenderObjectToWidgetAdapter.attachToRenderTree.<anonymous closure> (package:flutter/src/widgets/binding.dart:774:17)
E/flutter (17819): #10     BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2214:19)
E/flutter (17819): #11     RenderObjectToWidgetAdapter.attachToRenderTree (package:flutter/src/widgets/binding.dart:773:13)
E/flutter (17819): #12     _WidgetsFlutterBinding&BindingBase&GestureBinding&ServicesBinding&SchedulerBinding&PaintingBinding&RendererBinding&WidgetsBinding.attachRootWidget (package:flutter/src/widgets/binding.dart:662:7)
E/flutter (17819): #13     runApp (package:flutter/src/widgets/binding.dart:704:7)
E/flutter (17819): #14     main (file:///home/matejm/Desktop/flutter_screen/example/lib/main.dart:4:16)
E/flutter (17819): #15     _startIsolate.<anonymous closure> (dart:isolate/runtime/libisolate_patch.dart:279:19)
E/flutter (17819): #16     _RawReceivePortImpl._handleMessage (dart:isolate/runtime/libisolate_patch.dart:165:12)

It is probably because Dart 2.0 introduces strong types, which do not allow implicit casting.

I am going to create a pull request that fixes this problem (at least for me).

On IOS, Screen.setBrightness only works the first time

I have it set on a particular screen to set it to 75%, but if the user navigates away from that screen and sets the brightness to lower, then goes back to that screen, it will not reset the brightness.

I am on IOS 13.2, XCode 11.2.1 (11B500), and Flutter (Channel master, v1.12.4-pre.4, on Mac OS X 10.14.6 18G95, locale en-US)

Deprecated version of the Android embedding

The plugins `screen` use a deprecated version of the Android embedding.

To avoid unexpected runtime failures, or future build failures, try to see if these plugins support the Android V2 embedding. Otherwise, consider removing them since a future release of Flutter will remove these deprecated APIs.
If you are plugin author, take a look at the docs for migrating the plugin to the V2 embedding: https://flutter.dev/go/android-plugin-migration.

Reset user brightness / Turn off plugin

It might be related to this comment: #8 (comment)

It would be great to have a way to reset the user brightness, but more like turning off the plugin.

This is because (as the related comment says) it becomes impossible to manually change the brightness.

// on initState, get original brightness.
_userBrightnessRatio = await Screen.brightness;
...
// This correctly sets the original brightness back, but
// there is no way to change it using the user preferences.
// You need to close the app to be able to change it.
Screen.setBrightness(_userBrightnessRatio);

Do you believe there is a way to do this? I thought of adding the proper method to the https://github.com/clovisnicolas/flutter_screen/blob/master/android/src/main/java/flutter/plugins/screen/screen/ScreenPlugin.java file. I would be willing to create a PR if we could find a solution 😁.

Doesn't work with new flutter

I'm trying to use the plugin with flutter 1.7 but I'm always getting this error

E/flutter (22188): [ERROR:flutter/lib/ui/ui_dart_state.cc(148)] Unhandled Exception: MissingPluginException(No implementation found for method keepOn on channel github.com/clovisnicolas/flutter_screen)
E/flutter (22188): #0 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:314:7)
E/flutter (22188):
E/flutter (22188): #1 Screen.keepOn (package:screen/screen.dart:11:45)

Seems like some dependencies are missing. I tried rebuilding the app completely. It didn't help

Package transfer

Hey @clovisnicolas,

I'm wondering if you're open to transfer the package on pub.dev, since you haven't done any maintenance in four years. Please let me know.

screen 0.0.3 requires Dart SDK version <2.0.0

Hej can you remove the SDK restriction version?
I received The current Dart SDK version is 2.1.0-dev.0.0.flutter-be6309690f.

Because screen 0.0.3 requires SDK version <2.0.0 and no versions of screen match >0.0.3 <0.1.0, screen ^0.0.3 is forbidden.
So, because depends on screen ^0.0.3, version solving failed.
pub get failed (1)

Thanks in advance!

The brightness value got by Screen.brightness is different from the value of device brightness

Hi,

The version of my testing device is android7.1.1, I found if the adaptive brightness feature is enable, the brightness got by Screen.brightness is different from the actual value of the device brightness.

If I disable the adaptive brightness, the brightness value will be the same as the device brightness, so what can i do to get the actual brightness value when the device enable the adaptive brightness feature??

Thanks!!!!

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.