'How to screen off or lock the device by clicking our app icon in flutter

I want to turn off / lock the screen of my device by the clicking the icon of my app in flutter.

Like some new Android devices have this functionality.

Anyone Please guide me.

I am at beginner level in flutter.



Solution 1:[1]

The feature you are asking for needs native implications. The question has already been answered in one of the forum. It can be a bit tricky to implement. Have a look at the form link below

stack overflow solution

Solution 2:[2]

There are couple of plugins out there you can check them

flutter_screen_lock

flutter_lock_screen

Solution 3:[3]

you can use this plugin device_policy_manager it helps to lock the device immediately as if the lock screen timeout has expired at the point of this call. just follow the installation steps in the readme and this how u can use it


/// Return `true` if the given administrator component is currently active (enabled) in the system.
final status = await DevicePolicyManager.isPermissionGranted();

/// request administrator permission
await DevicePolicyManager.requestPermession("Your app is requesting the Adminstration permission");

/// lock the phone
await DevicePolicyManager.lockNow();

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rafat Rashid Rahi
Solution 2 saytoonz
Solution 3 Iheb Briki