Flutter plugin that allows you to keep the device screen awake on Android, iOS, macOS, Windows, and web.

Overview

Wakelock GitHub stars Pub version Twitter Follow

Wakelock is Flutter plugin that allows you to keep the device screen awake, i.e. prevent the screen from sleeping.

Supported platforms

Platform wakelock support
Android
iOS
Web
macOS
Windows
Linux planned

Getting started

To learn more about the plugin and getting started, you can view the main package (wakelock) README.

Plugin structure

The wakelock plugin uses the federated plugins approach.
For this plugin, it means that the basic API is defined using pigeon. The pigeon files can be found in the pigeons directory in the main package. The API is defined in Dart in the wakelock_platform_interface package.
Furthermore, the Android and iOS implementations can be found in the main package, while the web implementation is in the wakelock_web package.

The packages in this repo are the following:

Package Implementations
wakelock Main plugin package + Android & iOS implementations
wakelock_macos macOS implementation
wakelock_platform_interface Basic API definition & message handling
wakelock_web Web implementation
wakelock_windows Windows implementation

Contributing

If you want to contribute to this plugin, follow the contributing guide.

Origin

Originally, this plugin was based on screen.
Specifically, the wakelock functionality was extracted into this plugin due to lack of maintenance by the author of the screen plugin.

Today, the wakelock plugin has been completely refreshed (using latest Flutter standards and platform integration) with added support for web, Windows, & macOS.

Comments
  • 0.5.4 - crashes on launch on iOS

    0.5.4 - crashes on launch on iOS

    Previous versions worked fine but 0.5.4 crashes on launch on iOS with the following error shown in Xcode:

    Exception NSException * "FLTWakelockApi api doesn't respond to @selector(toggleMsg:error:)" 0x00000002813c23a0

    [✓] Flutter (Channel stable, 2.5.0, on macOS 11.5.2 20G95 darwin-x64, locale en-GB)
        • Flutter version 2.5.0 at /Users/per/dev/flutter
        • Upstream repository https://github.com/flutter/flutter.git
        • Framework revision 4cc385b4b8 (2 days ago), 2021-09-07 23:01:49 -0700
        • Engine revision f0826da7ef
        • Dart version 2.14.0
    
    [✓] Xcode - develop for iOS and macOS
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Xcode 12.5.1, Build version 12E507
        • CocoaPods version 1.11.0
    
    opened by PerLycke 29
  • `Wakelock.enable()` does not work on Android

    `Wakelock.enable()` does not work on Android

    I just created a bank flutter application and added Wakelock.enable(); as the first line inside main() method. I doesn't prevent my app from going to sleep.

    requires further investigation waiting for response 
    opened by rohitvishwakarma1819 19
  • iOS 13.4.1 goes always in standby

    iOS 13.4.1 goes always in standby

    i tried this ones to keep awake a iOS device (iOS 13.4.1 , iPhone 11 Pro Max):

          await Wakelock.enable();
          await Wakelock.toggle(on: true);
    

    every function called without an catched error, but no matter, which function, always go the device in black screen (standby).

    is this a bug in the plugin. when the functions are called on iOS 13.4.1 devices?

    i know for some weeks, the plugin works fine on iOS and the device skipped standby.

    bug requires further investigation 
    opened by maerlynflagg 18
  • 'Flutter/Flutter.h' file not found on Flutter 2.0.1

    'Flutter/Flutter.h' file not found on Flutter 2.0.1

    My project is not ready for nullsafety, and still use wakelock-0.2.1+1, its generate following error while running the application

    1 error generated. /Library/Developer/flutter/.pub-cache/hosted/pub.dartlang.org/wakelock-0.2.1+1/ios/Classes/messages.m:4:9: fatal error: 'Flutter/Flutter.h' file not found #import <Flutter/Flutter.h> ^~~~~~~~~~~~~~~~~~~

    its only happened with latest flutter version (2.0.1), when i downgrade it to 1.22.6, its working really fine, is there any ways to solve this?

    Flutter doctor result : Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.0.1, on macOS 11.2.2 20D80 darwin-x64, locale en-ID) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] VS Code (version 1.54.0) [✓] Connected device (4 available)

    bug requires further investigation p0 
    opened by nizwar 16
  • Added web support

    Added web support

    Hello, I initially added web support on this based on the WakeLock API https://developer.mozilla.org/en-US/docs/Web/API/Screen_Wake_Lock_API

    But the API is very young and limited in browser support having been released this year. But I came across a JS Library that not only does support the new API but has support for older/unsupported browsers because it has been developed way before it https://github.com/richtr/NoSleep.js/

    So I modified the library and basically wrapped it. I removed the Webpack/CommonJS parts because it wasn't sitting well with Dart's JS interoperability. I also added an isEnabled function but that would only be applicable for older browsers that doesn't support the new API because of this next reason

    The new APIs are async in nature which means I don't get an immediate response (WakeLockSentinel), So if I were to use the isEnabled function's return value to check if the WakeLockSentinel https://developer.mozilla.org/en-US/docs/Web/API/WakeLockSentinel is null or not then I won't get an updated value on the Dart side of the app. I mean I could modify the JS function with async/await syntax and await that on the Dart code but doing so, I would then break compatibility for older browsers that doesn't support async/await. So I wanted to preserve that backwards compatibility. So what I did was if the browser supports the native API then it would give an immediate boolean response on the isEnabled function, So if I were to toggle it on, It would return true. I mean as long the API is supported it would work just fine. It's just not reliable to check if the WakeLockSentinel is null immediately without using async/await. I also added some notes on the Dart code, so do check it out

    I hope you review and consider adding this

    Best regards

    opened by roulljdh 16
  • Plugin project :import_js_library not found.

    Plugin project :import_js_library not found.

    I've seen the error message "Plugin project :import_js_library not found. Please update settings.gradle." in the console on every flutter run (on Windows, targeting an Android device) after I updated wakelock to 0.2.0+1. Despite the error, wakelock seems to be working fine.

    Is there anything missing on the plugin side, or do I need additional configurations to run the app without the error?

    requires further investigation waiting for response 
    opened by kaboc 15
  • Unable to establish connection on channel

    Unable to establish connection on channel

    Hi,

    I'm getting this error when enabling wakelock:

    /flutter ( 3917): [ERROR:flutter/lib/ui/ui_dart_state.cc(186)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null) E/flutter ( 3917): #0 WakelockApi.toggle package:wakelock_platform_interface/messages.dart:57 E/flutter ( 3917): E/flutter ( 3917): #1 MethodChannelWakelock.toggle package:wakelock_platform_interface/method_channel_wakelock.dart:20 E/flutter ( 3917): E/flutter ( 3917):

    And it does not work. I did flutter clean but it does not help.

    Doctor summary (to see all details, run flutter doctor -v): [✓] Flutter (Channel stable, 2.0.6, on macOS 11.4 20F71 darwin-x64, locale pl-PL) [✓] Android toolchain - develop for Android devices (Android SDK version 30.0.2) [✓] Xcode - develop for iOS and macOS [✓] Chrome - develop for the web [✓] Android Studio (version 4.1) [✓] VS Code (version 1.57.1) [✓] Connected device (2 available)

    • No issues found!

    opened by mklepaczko 14
  • Wakelock requires a foreground activity

    Wakelock requires a foreground activity

    Hi - I'm consistently seeing this exception on Android:

    Exception has occurred.
    PlatformException (PlatformException(no_activity, wakelock requires a foreground activity, null))
    

    As best I can tell, I have a foreground activity (if that means that the app is in the foreground at the point it happens).

    Any idea why it's happening? Many thanks.

    bug requires further investigation waiting for response 
    opened by shinyford 13
  • Error while using the plugin.

    Error while using the plugin.

    Unable to complete build process after importing wakelock.dart file in my flutter application.

    The error is shown as above. A build for MacOS is working fine. It is just with Android. Haven't tested with iOS.

    bug requires further investigation waiting for response 
    opened by kphanipavan 9
  • Wakelock 0.5.4 might not work on Android?

    Wakelock 0.5.4 might not work on Android?

    I recently upgraded to Flutter 2.5 stable. I use Wakelock only on a specific screen of my app where it is necessary. At the beginning of initState I call Wakelock.enable() (without await since the initState is not async) and in dispose (which is similarly not async) I call Wakelock.disable(). This worked beofre but for some reaosn it does not work now and the phone (OnePlus Nord, Android 11) goes to sleep like a baby. Not sure if it was definitely the 2.5 Flutter update since I'm dealing with code churn, but I don't know what else. I wonder if anyone else has this problem.

    requires further investigation 
    opened by MrCsabaToth 8
  • FCMService: Invalid notification content

    FCMService: Invalid notification content

    i am getting this error about FCM after importing wakelock library in my flutter project:

    D/FCMService: FCM received
    D/FCMService: Invalid notification content
    

    but if i remove the wakelock plugin from my dependencies list , it works well as it was working before! what's wrong?

    bug requires further investigation 
    opened by benyamin218118 8
  • Can't disable wake lock on iOS

    Can't disable wake lock on iOS

    Works fine on android, but on iOS both Wakelock.disable() and Wakelock.toggle(enable: false) are called without any error, but screen stays on forever. No error or exception thrown, The code was called, but nothing happened.. As soon as I let the app the screen dimmed as expected. Tested on real device, iPhone 11, iOS 15.4.1

    Super simple code: (Tried with and without awaiting, no change)

    ElevatedButton( onPressed: () async { try { if (await Wakelock.enabled) { // await Wakelock.enable(); await Wakelock.toggle(enable: false); } else { // await Wakelock.disable(); await Wakelock.toggle(enable: true); } } catch (error) { print(error); } },

    opened by EinatK 0
  • Message corrupted, Failed to handle message

    Message corrupted, Failed to handle message

    Got the below issue, I'm on flutter 3.3.0:

    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): Failed to handle message
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): java.lang.IllegalArgumentException: Message corrupted
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:450)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.plugin.common.StandardMessageCodec.readValueOfType(StandardMessageCodec.java:424)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.plugin.common.StandardMessageCodec.readValue(StandardMessageCodec.java:340)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.plugin.common.StandardMessageCodec.decodeMessage(StandardMessageCodec.java:89)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.plugin.common.BasicMessageChannel$IncomingMessageHandler.onMessage(BasicMessageChannel.java:218)
    [GETX] Instance "SongController" has been initialized
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$DartMessenger(DartMessenger.java:319)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at io.flutter.embedding.engine.dart.-$$Lambda$DartMessenger$TsixYUB5E6FpKhMtCSQVHKE89gQ.run(Unknown Source:12)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at android.os.Handler.handleCallback(Handler.java:938)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at android.os.Handler.dispatchMessage(Handler.java:99)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at android.os.Looper.loopOnce(Looper.java:226)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at android.os.Looper.loop(Looper.java:313)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at android.app.ActivityThread.main(ActivityThread.java:8669)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at java.lang.reflect.Method.invoke(Native Method)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
    E/BasicMessageChannel#dev.flutter.pigeon.WakelockApi.toggle(24941): 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)
    E/flutter (24941): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(channel-error, Unable to establish connection on channel., null, null)
    E/flutter (24941): #0      WakelockApi.toggle (package:wakelock_platform_interface/messages.dart:89:7)
    E/flutter (24941): <asynchronous suspension>
    E/flutter (24941): #1      MethodChannelWakelock.toggle (package:wakelock_platform_interface/method_channel_wakelock.dart:20:5)
    E/flutter (24941): <asynchronous suspension>
    
    requires further investigation 
    opened by jbj88817 3
  • Web - TypeError: Cannot read properties of undefined (reading 'toggle')

    Web - TypeError: Cannot read properties of undefined (reading 'toggle')

    Calling Wakelock.enable() within the main function throws a TypeError when running against web.

    void main() {
      WidgetsFlutterBinding.ensureInitialized();
      Wakelock.enable();
      runApp(const MyApp());
    }
    
    TypeError: Cannot read properties of undefined (reading 'toggle')
    at toggle (http://localhost:52933/packages/wakelock_web/wakelock_web.dart.lib.js:35:30)
        at toggle.next (<anonymous>)
        at runBody (http://localhost:52933/dart_sdk.js:40660:34)
        at Object._async [as async] (http://localhost:52933/dart_sdk.js:40691:7)
    at wakelock_web.WakelockWeb.new.toggle (http://localhost:52933/packages/wakelock_web/wakelock_web.dart.lib.js:34:20)
    at Function.toggle (http://localhost:52933/packages/wakelock/wakelock.dart.lib.js:26:48)
    at Function.enable (http://localhost:52933/packages/wakelock/wakelock.dart.lib.js:19:32)
    at main$ (http://localhost:52933/packages/flutter_application_1/main.dart.lib.js:285:23)
    at http://localhost:52933/web_entrypoint.dart.lib.js:37:33
        at Object._checkAndCall (http://localhost:52933/dart_sdk.js:5279:16)
        at Object.dcall (http://localhost:52933/dart_sdk.js:5284:17)
        at http://localhost:52933/dart_sdk.js:140291:18
    

    This was replicated in a new project with only the addition of the Wakelock package.

    App Code That Replicates Issue
    import 'package:flutter/material.dart';
    import 'package:wakelock/wakelock.dart';
    
    void main() {
      WidgetsFlutterBinding.ensureInitialized();
      Wakelock.enable();
      runApp(const MyApp());
    }
    
    class MyApp extends StatelessWidget {
      const MyApp({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return MaterialApp(
          title: 'Flutter Demo',
          theme: ThemeData(),
          home: const HomeScreen(),
        );
      }
    }
    
    class HomeScreen extends StatelessWidget {
      const HomeScreen({Key? key}) : super(key: key);
    
      @override
      Widget build(BuildContext context) {
        return const Scaffold(body: Center(child: Text('Home')));
      }
    }
    
    ...
    dependencies:
      flutter:
        sdk: flutter
    
      wakelock: 0.6.1+2
    ...
    
    
    Flutter Doctor Output

    [✓] Flutter (Channel unknown, 3.0.1, on macOS 11.6.5 20G527 darwin-x64, locale en-US) [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) [✓] Xcode - develop for iOS and macOS (Xcode 13.0) [✓] Chrome - develop for the web [✓] Android Studio (version 2020.3) [✓] Android Studio (version 4.1) [✓] VS Code (version 1.67.2) [✓] Connected device (4 available) [✓] HTTP Host Availability

    • No issues found!

    opened by alexagat 3
  • iOS Wakelock does not avoid dimming screen

    iOS Wakelock does not avoid dimming screen

    Hi, mi app is a game where players have to think for a while. So sometimes they are meditating and not interacting at all. I only have timers running at the time. I added the wakelock.enabled command after installing the plugin but I see that the screen dims and then closes according to the time set in the AutoLock field in Display and Brightness for the iOS device. Is it not the plugins mission to avoid the screen from dimming?

    requires further investigation 
    opened by danielefolatelli 3
  • `Wakelock.enable()` changes system Ui overlay style on Android

    `Wakelock.enable()` changes system Ui overlay style on Android

    Calling Wakelock.enable changes system Ui overlay style to the one default of the system. In particularly, this changes the status bar icon brightness. This was tested on Android. Simply call Wakelock.enable after setSystemUIOverlayStyle with a different status bar icon brightness from the one of the system.

    I suspect this isn't due to the Android plugin or the Flutter interface but due to the Android system and it's wakelock flag. Currently, I circumvent this by setting my custom overlay style based on my own app theme before and after the Wakelock call, since I enable it with low priority later in the initialization.

    EDIT: I wasn't able to solve it by setting the overlay after the Wakelock call, I was forced to disable Wakelock (not call Wakelock.enable).

    requires further investigation 
    opened by Stemo688 5
Releases(wakelock_windows-v0.2.1)
An E-Commerce application developed on Flutter, which helps to run the app on Android / IOS / Windows's OS / MacOS / Web Browser from a single codebase

BuySmart An E-Commerce application developed on Flutter, which helps to run the app on Android / IOS / Windows's OS / MacOS / Web Browser from a singl

Sumit Kumar 11 Oct 10, 2022
Movies application (Cubit, Android, iOS, macOS, Web, Windows)

Movies App (Cubit) Movies Application Platforms 1 - Android 2 - iOS 3 - macOS 4 - Web 5 - Windows Libraries & Tools Flutter 3.0.1 • channel stable Da

Alexandr Zherebtsov 1 Jun 7, 2022
Yukino lets you read manga or stream anime ad-free from multiple sources for free! Available for Windows, Linux, MacOS and Android.

Yukino Yukino lets you read manga or stream anime ad-free from multiple sources. The project's name "Yukino" meaning "Snow" named after the character

Yukino 204 Jan 6, 2023
A Dart Build Plugin that uploads debug symbols for Android, iOS/macOS and source maps for Web to Sentry via sentry-cli

Sentry Dart Plugin A Dart Build Plugin that uploads debug symbols for Android, iOS/macOS and source maps for Web to Sentry via sentry-cli. For doing i

Sentry 36 Jan 4, 2023
A Flutter plugin that provides assets abstraction management APIs without UI integration, you can get assets (image/video/audio) on Android, iOS and macOS.

photo_manager Photo/Assets management APIs for Flutter without UI integration, you can get assets (image/video/audio) from Android, iOS and macOS. 提供相

FlutterCandies 526 Jan 4, 2023
Android test task master - Create PIN code screen, authentication by PIN code screen and menu screen

Here is described test tasks for a android dev. Need to implement three screens:

null 3 Oct 4, 2022
A flutter plugin to query Android device Administrator (DevicePolicyManager) particulary Locking screen

device_policy_manager A flutter plugin to query Android device Administrator (DevicePolicyManager) particulary Locking screen for more info check Devi

Iheb Briki 4 Sep 29, 2022
A user-friendly money management app which allows you to keep track of transactions seamlessly

See the first version of 'Mvelopes' - Money Management Application which I completed as my first project and published on Play Store. 'Mvelopes' is a user-friendly money management app which allows you to keep track of transactions seamlessly. - Features - Technology • Reminder • Flutter • Notification • Hive • Manage income & expenses

Mushthak 16 Dec 8, 2022
Responsive Blog Theme using Flutter | Web, macOS, Android, iOS

Responsive Blog Theme using Flutter | Web, macOS, Android, iOS Watch it on YouTube Packages we are using: flutter_svg: link get: link Flutter recently

Abu Anwar 196 Dec 9, 2022
Doctor Consultation App in Flutter containing splash screen on boarding screen Routing state management Dash board Bottom navigation Decorated Drawer and Doctors Screen in the last.

Online doctor Consultation App UI in Flutter Doctor Consultation App UI in Flutter Visit Website Features State Management Navigation Bar Responsive D

Habib ullah 14 Jan 1, 2023
Resource monitor - A flutter plugin for Android and IOS to monitor CPU and RAM usage of device.

resource_monitor A flutter plugin for Android and IOS to monitor CPU and RAM usage of device. TODO Return overall system cpu/memory usage. Implement A

Skandar Munir 1 Nov 11, 2022
A Gitmoji app for macOS, Linux, and Windows.

GitmojiApp A Gitmoji app for macOS, Linux, and Windows. macOS Linux Windows What is this GitmojiApp is a simple desktop app that allows you to add a G

Patrick Fu 11 Dec 24, 2022
A Flutter plugin for iOS and Android allowing access to the device cameras.

Camera Plugin A Flutter plugin for iOS and Android allowing access to the device cameras. Note: This plugin is still under development, and some APIs

Rebar Ahmad 1 Mar 17, 2020
A Flutter plugin for Android and iOS allowing access to the device cameras, a bit deeper!!

flutter_cameraview A Flutter plugin for Android and iOS allowing access to the device cameras, a bit deeper!!. This plugin was created to offer more a

Herizo Ramaroson 18 Oct 22, 2022
A Flutter plugin for iOS and Android allowing access to the device cameras.

A Flutter plugin for iOS and Android allowing access to the device cameras.

Lightsnap 140 Jan 8, 2023
A Flutter plugin to request the device unlock screen.

device_unlock A Flutter plugin to request the device unlock screen on Android and iOS. How does it work The following attempts and fallbacks are made:

Cíngulo 19 Sep 7, 2022
SSH no ports provides ssh to a remote Linux device with out that device having any ports open

Ssh! No ports ssh no ports provides a way to ssh to a remote linux host/device without that device having any open ports (not even 22) on external int

The Atsign Foundation 224 Dec 21, 2022
A Flutter plugin which allows you to execute code in the background on Android and iOS.

Flutter Workmanager Flutter WorkManager is a wrapper around Android's WorkManager, iOS' performFetchWithCompletionHandler and iOS BGAppRefreshTask, ef

Flutter Community 699 Jan 5, 2023
A Flutter plugin for changing the Home Screen, Lock Screen (or both) Wallpaper on Android devices.

wallpaper_manager A Flutter plugin for changing the Home Screen, Lock Screen (or both) Wallpaper(s) on Android devices. Usage Installation In the pubs

Aditya Mulgundkar 38 Nov 28, 2022