Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to keep application awake in flutter?

Tags:

flutter

How to keep an application from locking the screen in flutter?

Is there a flag to turn it off an on? Does flutter SDK expose this?

Something like keepAwake(true);

Thank you

like image 431
Tree Avatar asked Apr 06 '18 02:04

Tree


People also ask

How do you keep your screen awake in Flutter?

The plugin allows you to enable and toggle the screen wakelock, which prevents the screen from turning off automatically. Essentially, this allows you to keep the device awake, i.e. prevent the device from sleeping.

How do I make my apps run in the background on Flutter?

A plugin to keep flutter apps running in the background. Currently only works with Android. It achieves this functionality by running an Android foreground service in combination with a partial wake lock and disabling battery optimizations in order to keep the flutter isolate running.

How do I turn off screen Flutter?

Usage. Import KeepScreenOn. To keep the screen from turning off, call the turnOn method of the KeepScreenOn class. Calling the turnOff method of the KeepScreenOn class will restore the screen to turn off automatically.

Are Flutter apps stable?

We have all of the six major platforms – iOS, Android, web, Windows, macOS, Linux – all supported as stable parts of the Flutter framework."


1 Answers

As support for the screen plugin that @Tree mentioned has been discontinued and there are some issues with it now, you can use wakelock.
Full disclosure: I am the author of this plugin, however, it is basically a port of the wakelock functionality from the screen plugin, with the issues fixed:

import 'package:wakelock/wakelock.dart';  // To keep the screen on: Wakelock.enable(); // or Wakelock.toggle(on: true);  // To let the screen turn off again: Wakelock.disable(); // or Wakelock.toggle(on: false); 

Learn more.

like image 108
creativecreatorormaybenot Avatar answered Sep 20 '22 10:09

creativecreatorormaybenot