Flutter detect if screen off

Viewed 6221

I am currently writing an app, and records some info (eg GPS), even if screen is off (ie its screen has timed out in sleep mode).

It performs a setState() every so often to update the Widgets.

However, if the screen is asleep/inactive, I'm not sure there is a need to call setState(), or certain other cpu intensive actions, and may be better to preserve battery by not calling it ?

So, I am wondering if there is any way to detect if the screen is off, and hence not call setState..

eg in pseudocode

if( checkScreenIsOn() ) { setState((){...})}

I'm unsure if some event is triggered when the screen goes off that flutter sees. Also if things like GPS, I'd like to record normally when the screen is off (I'm currently using a listener), but not update the display. Does GPS go into a different mode, and any way to stop that if so ?

1 Answers
Related