Flutter: Turn off screen when phone close to face

491

I was able to know with this plugin proximity_sensor

Share:
491
Zhu
Author by

Zhu

Updated on November 23, 2022

Comments

  • Zhu
    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
      Chirag Bargoojar almost 3 years
      Use 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 using wakelock package pub.dev/packages/wakelock/install
    • Zhu
      Zhu almost 3 years
      Thanks @ChiragBargoojar, I couldn't compile with all_sensors, now I'm using proximity_sensor:
    • Chirag Bargoojar
      Chirag Bargoojar almost 3 years
      You need to up your minSDKVersion to 19 inside app/build.gradle because all_sensor package requires minSDKVersion of 19
    • Zhu
      Zhu almost 3 years
      Mine is already 21 minSDK
    • Chirag Bargoojar
      Chirag Bargoojar almost 3 years
      This is the example using all_sensors package. pub.dev/packages/all_sensors/example