title: Flutter use WidgetsBindingObserver only when on top of the stack
body: <p>I have a <code>StatefulWidget</code> and at the beginning of the State method's build I do</p>
  <pre><code>WidgetsBinding.instance
          .addObserver(LifecycleEventHandler(resumeCallBack: () async {
        if (mounted) {
          refreshState();
        }
      }));
  </code></pre>
  <p>This is the code of the <code>LifecycleEventHandler</code></p>
  <pre><code>class LifecycleEventHandler extends WidgetsBindingObserver {
    final AsyncCallback resumeCallBack;
  
    LifecycleEventHandler({
      this.resumeCallBack,
    });
  
    @override
    Future&lt;void&gt; didChangeAppLifecycleState(AppLifecycleState state) async {
      switch (state) {
        case AppLifecycleState.resumed:
          if (resumeCallBack != null) {
            await resumeCallBack();
          }
          break;
        case AppLifecycleState.inactive:
          break;
        case AppLifecycleState.paused:
          break;
        case AppLifecycleState.detached:
          break;
      }
    }
  }
  </code></pre>
  <p>the <code>resumeCallBack</code> is being called every time the app is resumed, even if the page is not visible to the user (if I navigate to another page without removing this from the stack).</p>
  <p>Is there a way to run this callback only if the page is visible to the user? I don't want to dispose the state/page but just avoid unnecessary state updates</p>