How to detect if Flutter webview is in foreground or background? - flutter

I have a requirement where I need to record the time user spends viewing a certain attachment. I am opening the item in an external webview provided by flutter_inappwebview package on pub.dev.
Now to detect the amount of time user is spending I run timers. I want these timers to stop when the app is not in foreground, so I used Flutter's lifecycle events to detect this. The problem is, as soon as the webview is opened, the lifecycle event paused is called. Now i don't know if the user is viewing the item or has pushed the app to background.
Any leads will be helpful thanks.
I tried using flutter's lifecycle events, but they fire as soon as webview is launched and does not fire any other events after the webview is opened until user comes back to the app.

Related

How to run timer even app in background or foreground in flutter?

i want to hide button for specific time when user tapped on button, and the button show when time is completed, even app in foreground or background
the ultimate solution is to use foreground services, and with android, it comes with a sticky notification to prevent the system from killing the app.

Notification Timer should continue even if app is close without another notification

In my app there is condition where a notification is generated at button click and showing with Countdown it is working fine if app is open. With the help of background service notification timer also working fine even if app is close but I have to show extra notification for Background service in Android devices.
I am using flutter_local_notifications: ^9.2.0 and flutter_background_service: ^2.3.9
Is there any way to achieve my goal without background service and without extra notification.

Is there a way to display a specific Flutter page when screen is locked?

please is there a way to display or open a Flutter page when screen is locked in Flutter like how WhatsApp displays incoming call page when screen is locked? I used Wake up plugin but can't display the page on screen locked. Please I need a guide to do that. Thanks in advance.
What you are looking for is called a time sensitive notification with a full screen notification. What it does is that if the screen is locked it opens the activity linked to the pending intent used for full screen notification. When the phone is unlocked, it shows a heads up notification instead. You must have seen this behavior with all kinds of telephony apps and alarm apps.
A flutter app runs inside a single activity, so if you mark that as the activity to show during the locked state, the app will show. But it will act similar to how the app would when you launch it from start. Also the behavior is unpredictable as it is behind a wakelock. So a better option would be to move it to a separate activity and do the needful. Example of how to implement full screen notifications.
https://medium.com/android-news/full-screen-intent-notifications-android-85ea2f5b5dc1

Trigger an action when timer expires in the background

I’ve developed a Xcode app to trigger an action on timer expiry. This works fine when the app is visible on the device. However when the app is minimised eg. the Home button is pressed, the app doesn’t work. It seems like the app gets suspended. It resumes the countdown when it is brought to the foreground again.
Any guidance will be appreciated.
Timers will only run in the background if your app is running in the background for another reason. You will need to enable a background mode on the capabilities page. Your timer will also need to have already started when you enter the background
This may also be helpful:
https://www.raywenderlich.com/5817-background-modes-tutorial-getting-started

Their is any way to detect my app goes in background state or killed when i'm on any screen of my app in Flutter

Their is any way to detect my app goes in background state or killed when i'm on any screen of my app in Flutter instead of using WidgetsBindingObserver on every screen. i have update offline status on firebase server when app is minimized or killed and when it relaunched then it will be online. I am able to identify this on a particular screen but i have to handle it on every screen, so that we can handle on every screen approach is wrong can their is any other way?.