How to display total time user active inside the APP

37 views
Skip to first unread message

Madan Raj

unread,
Oct 7, 2020, 1:54:14 PM10/7/20
to Flutter Development (flutter-dev)
i have been developing  app in flutter and now got stuck in one fucntionality 
that is i want to store the total time app been used by the user and store that time in hours 
i have searched but didn't find any useful result 
is that even possible in flutter ? 
please help me 

Hugo van Galen

unread,
Oct 8, 2020, 5:29:46 AM10/8/20
to Madan Raj, Flutter Development (flutter-dev)
Yeah, sure this is possible in Flutter.  You probably want to read into Flutter AppLifecycle events. Using those, you can determine when the app is active and stops being active. You simply need to keep track of time-stamps between these events (and probably need to store them via the `shared_preferences` plugin). 

Note that you would need to store the time in a higher resolution than hours though, like in seconds. If you use hours, and the user used your app for 30 seconds -- that would round to '0' hours, and would eventually add nothing to the total active time. So store it in seconds, and when you request the value, divide it by 3600 to get the number of hours.

Hope this helps.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/8a1c85a5-768a-464a-b6e4-0b2a96e84f9fn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages