0

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 1

0

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.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.