VOOZH about

URL: https://www.geeksforgeeks.org/flutter/flutter-wakelock/

⇱ Flutter Wakelock - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Flutter Wakelock

Last Updated : 23 Jul, 2025

The wakelock_plus package in Flutter is used to keep the screen awake. It can be adjusted according to the requirements (how long to stay awake). These are straightforward things that enhance the quality of the app and increase the user-friendliness of the same.

In this article, we will explore the process of keeping the mobile screen awake while not using the application. To do so, we will build a simple application with two buttons, namely:

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

Steps to implement wakelock in the Flutter application

Step 1 : Create a new Flutter Application

Create a new Flutter application using the command Prompt. To create a new app, write the below command and run it.

flutter create app_name

To know more about it refer this article: Creating a Simple Application in Flutter


Step 2 : Adding the Dependency

To add the dependency to the pubspec.yaml file, add wakelock_plus as a dependency in the dependencies part of the pubspec.yaml file, as shown below:

Now run the below command in the terminal.

flutter pub get


Step 3 : Importing the Dependency

Use the below line of code in the main.dart file to import the wakelock_plus dependency.

import 'package:wakelock_plus/wakelock_plus.dart';


Step 4 : Creating an application structure

The StatefulWidget can be used to give a simple structure to the application as shown below:


Step 5 : Adding Buttons

One of the ways to add buttons in an application is to use the inbuilt OutlineButton widget in flutter. These are simple to implement and as discussed earlier, we will add two buttons to the body of the application namely: enable wakelock and disable wakelock as shown below:

To know more about ElevatedButton in Flutter refer this article: Flutter – ElevatedButton Widget.

Complete Source Code

main.dart:


Output:

👁 wake


Since the output is not possible to show in any form unless tried by yourself, use the above source code and try it for yourself. The above output shows only the basic UI of the application we have built.

Comment
Article Tags:

Explore