3

I'm developing an app that works with sensitive information.

One of the requirements is that when a user puts the app in background the content that the app is currently displaying has to be hidden, so if another person navigate through the apps in background he can't see the last screen where the user was.

Any ideas on how to do that?

I tried to show an overlay when the app moves to AppLifecycleState.paused, but it doesn't work for me, the app prints a message if I want but it can't update the UI.

Jofre
  • 531
  • 7
  • 10
  • What have you tried? Are you using WidgetBindingObserve? – aksappy Jan 31 '20 at 14:56
  • Yes, and I override the didChangeAppLifecycleState method. – Jofre Jan 31 '20 at 14:58
  • And in that you cleared the state or navigated to another screen? – aksappy Jan 31 '20 at 14:59
  • `case AppLifecycleState.paused: setState(() { appInBackground = true; }); break;` – Jofre Jan 31 '20 at 15:01
  • The overlay idea comes from here: https://stackoverflow.com/questions/57069641/how-to-overlay-a-widget-on-top-of-a-flutter-app – Jofre Jan 31 '20 at 15:07
  • 2
    Well, now I know that you are not the only one facing this issue. And the android docs say that for this functionality resort to native code as much as possible. https://github.com/flutter/flutter/issues/33236 https://flutter.dev/docs/get-started/flutter-for/android-devs#how-do-i-listen-to-android-activity-lifecycle-events – aksappy Jan 31 '20 at 15:28

1 Answers1

6

Edit Shameless plug: i did a library for doing just that as I also needed it:

https://pub.dev/packages/secure_application

Answear

Build is not called after paused, at least on Android.

For Android I used a flutter_windowmanager package (modified to still be able to build on IOS):

https://github.com/neckaros/flutter_windowmanager

When my app need securing I add the flag secure:

FlutterWindowManager.addFlags(FlutterWindowManager.FLAG_SECURE)

And my app is now a black screen in the app switcher. You should still hide content your way for when the user get back to the app.

Otherwise you can go native: https://medium.com/@mehmetf_71205/securing-flutter-apps-ada13e806a69