Flutter: Turn off screen when phone close to face
491
I was able to know with this plugin proximity_sensor
Author by
Zhu
Updated on November 23, 2022Comments
-
Zhu over 1 year
I'm doing calling feature in Flutter and I need to know whether user wants to listen with earpeace and turn off the screen, set audio output to earpeace. Is there a sensor to know if phone is close to face/ear to turn off the screen ?
-
Chirag Bargoojar almost 3 yearsUse
all_sensors
package pub.dev/packages/all_sensors/install to get the value of proximity sensor which tells about how close the phone is to face or anything (returns true and false only). Now you get the value now you can make phone lock usingwakelock
package pub.dev/packages/wakelock/install -
Zhu almost 3 yearsThanks @ChiragBargoojar, I couldn't compile with all_sensors, now I'm using proximity_sensor:
-
Chirag Bargoojar almost 3 yearsYou need to up your minSDKVersion to 19 inside
app/build.gradle
becauseall_sensor
package requires minSDKVersion of 19 -
Zhu almost 3 yearsMine is already 21 minSDK
-
Chirag Bargoojar almost 3 yearsThis is the example using
all_sensors
package. pub.dev/packages/all_sensors/example
-