Can I detect changing of lifecycle state of PWA using WidgetsBindingObserver? In my app I have to show new content on a new day. For the mobile app I am able to use WidgetsBindingObserver to check when the app comes to foreground and run some task. Just wondering how to achieve something similar in flutter web app (mainly when it is saved as PWA on device).
1 Answer
No, you cannot reliably use WidgetsBindingObserver to detect lifecycle changes (like foreground/background) in Flutter web or PWA1. Instead, use the browser’s visibilitychange event via dart:html to detect when your app/tab becomes visible, and trigger your logic there
import 'dart:html' as html;
html.document.onVisibilityChange.listen((event) {
if (!html.document.hidden!) {
// App is visible; check for new content here
}
});
This approach works for PWAs and web apps.