How to Keep Application Awake In Flutter?

· 2 min read
How to Keep Application Awake In Flutter
How to Keep Application Awake In Flutter

Some apps in flutter require keeping it awake all the time. So in this article, we will go through How to Keep Application Awake In Flutter?

Are you ready for the same?

How to Keep Application Awake In Flutter?

As support for the Screen Plugin that has been discontinued and there are some issues with it now, you can use wake lock. The Wakelock package in Flutter keeps the screen awake while using it. According to the requirements (how long to stay awake) wakelock is adjusted.

Two buttons are used that is:

  • enable wakelock: It will prevent the phone screen to lock itself irrespective of how long it stays that way.
  • disable wakelock: It will disable the wakelock functionality of the application.

Firstly consider a code snippet like the below:

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);

After that import package like a below:

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

You will also need to set permission for an android.

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

Conclusion:

Thanks for being with us on a Flutter Journey !!!

So, In this article, We have been through How to Keep Application Awake In Flutter?

Do not forget to share your valuable suggestions/feedback with us much.

Flutter Agency is our portal Platform dedicated to Flutter Technology and Flutter Developers. The portal is full of cool resources from Flutter like Flutter Widget GuideFlutter ProjectsCode libs and etc.

Flutter Agency is one of the most popular online portals dedicated to Flutter Technology. And daily thousands of unique visitors come to this portal to enhance their knowledge of Flutter.

Leave a Reply