Reputation: 119
i need to lock and unlock device ( turning screen off and on like phone calls when the phone is close to your ear) .
i used proximity_plugin for proximity sensor listener but i can't find a way to turn off the screen
i used a black screen and full screen mode but i don't like this solution i need to make it same as phone calls ( what am i missing ? )
proximityEvents.listen((ProximityEvent event) async{
if(event.x == 'Yes'){
//enter full screen
SystemChrome.setEnabledSystemUIOverlays([]);
//show black screen
setState(() {
isLocked = true;
});
}else {
//exit full screen
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
//w8 150 mili sec then remove black screen
Future.delayed(const Duration(milliseconds: 150), () {
setState(() {
isLocked = false;
});
});
}
});
Upvotes: 2
Views: 379