title: Is there a way to repaint the screen or navigate to a different screen on AppLifecycleState.paused in Flutter
body: <p>I have a Flutter app that contains sensitive medial information and business wants this information to be hidden when the app is put into the background, including the Recent Apps screen. </p>
  
  <p>I have added WidgetsBindingObserver and am listening to the events correctly.  Resumed state correctly fires and sends user back to login page; however, the paused event doesn't do anything on receipt of the state.  For reference I have tried pushing a new screen onto the stack as well as popping all screens until reaching the login but neither works.</p>
  
  <pre><code>@override
    void didChangeAppLifecycleState(AppLifecycleState state) {
      super.didChangeAppLifecycleState(state);
      switch (state) {
        case AppLifecycleState.paused:
          Navigator.of(context).push(new PageRouteBuilder(
            pageBuilder: (_, __, ___) =&gt; new Splash(
                  inBackground: true,
                ),
          ));
          break;
        case AppLifecycleState.resumed:
          Navigator.of(context).pushNamed('/login');
          break;
        default:
          break;
      }
    }
  </code></pre>
  
  <p>I expect that when the paused event is received to be able to change the screen to protect this sensitive info.  Any ideas are welcome!</p>
  
  <p>EDIT: Most recent code.</p>
  
  <pre><code>import 'package:boxview_mobile_flutter/screens/splash/index.dart';
  import 'package:boxview_mobile_flutter/services/shared_prefs.dart';
  import 'package:firebase_messaging/firebase_messaging.dart';
  import 'package:flutter/material.dart';
  
  class PushNotifications extends StatefulWidget {
    @override
    _PushNotificationsState createState() =&gt; _PushNotificationsState();
  }
  
  class _PushNotificationsState extends State&lt;PushNotifications&gt; with WidgetsBindingObserver {
    bool loggedOut = false;
    final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
  
    @override
    Widget build(BuildContext context) {
      return Container(child: Splash(loggedOut: this.loggedOut));
    }
  
    @override
    void didChangeAppLifecycleState(AppLifecycleState state) {
      switch (state) {
        case AppLifecycleState.paused:
          print("Paused");
          break;
        case AppLifecycleState.inactive:
          print("inactive");
          setState(() {
            loggedOut = true;
          });
          break;
        case AppLifecycleState.suspending:
          print("suspending");
          break;
        case AppLifecycleState.resumed:
          setState(() {
            loggedOut = false;
          });
          print("resumed");
          break;
      }
    }
  
    @override
    void initState() {
      super.initState();
      WidgetsBinding.instance.addObserver(this);
      _firebaseMessaging.configure(
        onMessage: (Map&lt;String, dynamic&gt; message) async {
          print("onMessage: $message");
        },
        onLaunch: (Map&lt;String, dynamic&gt; message) async {
          print("onLaunch: $message");
        },
        onResume: (Map&lt;String, dynamic&gt; message) async {
          print("onResume: $message");
        },
      );
      _firebaseMessaging.requestNotificationPermissions(const IosNotificationSettings(sound: true, badge: true, alert: true));
      _firebaseMessaging.onIosSettingsRegistered.listen((IosNotificationSettings settings) {
        print("Settings registered: $settings");
      });
      _firebaseMessaging.getToken().then((String token) {
        assert(token != null);
        SharedPreferencesHelper.setFirebaseToken(token);
      });
    }
  
    @override
    void dispose() {
      WidgetsBinding.instance.removeObserver(this);
      super.dispose();
    }
  }
  </code></pre>
  
  <p>Splash is just a splash page and the boolean loggedOut param just says don't forward to login page.</p>