title: Flutter Riverpod: Refresh Page Offscreen using State Notifier
body: <p>I'm using StateNotifier and Riverpod.
  I have a notification page, which contains a list of notification. When a notification arrives, I trigger a refresh for notification. However, when I navigate to notification page, it still using the old (cached?) list.</p>
  <p>How do I refresh a page offscreen?</p>
  <h3>Foreground Message</h3>
  <pre><code>FirebaseMessaging.onMessage.listen((RemoteMessage message) {
    _localNotification.showLocalNotification(message);
    ProviderContainer().read(notificationProvider).getNotification();
  });
  </code></pre>
  <h3>Background Message</h3>
  <pre><code>Future&lt;void&gt; _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
    await Firebase.initializeApp();
  
    final LocalNotification localNotification = LocalNotification();
    await localNotification.init();
    localNotification.showLocalNotification(message);
    ProviderContainer().read(notificationProvider).getNotification();
  }
  </code></pre>
  <h3>NotificationProvider</h3>
  <pre><code>Future&lt;void&gt; getNotification() async {
    try {
      state = const NotificationLoadingState();
      _notificationList = await _notificationRepository.getNotification();
      state = NotificationLoadedState(_notificationList); // ==&gt; I get a new list here
    } catch (e, s) {
      state = const NotificationErrorState('error fetching notification');
    }
  }
  </code></pre>
  <h3>UI</h3>
  <pre><code>final state = watch(notificationProvider.state);
  if (state is NotificationLoadingState) {
    return _buildLoading();
  } else if (state is NotificationLoadedState) {
    return _buildLoaded(state.notificationList); // ==&gt; I still get the old list here
  } else if (state is NotificationErrorState) {
    return _buildError(state.message);
  }
  </code></pre>
  <h2>Edit:</h2>
  <p>I managed to solve the foreground message handler by using <code>navigatorKey.currentContext</code>.</p>
  <p>However, I still haven't solved background message handler.
  I've tried changing my <code>main.dart</code> to use <code>UncontrolledProviderScope</code> with a global <code>ProviderContainer</code>, which then was called from background message handler. It's still not refreshing.</p>