How to hide app preview when switching apps, with Flutter.

This is an important feature when your app displays sensitive data.

Carlo Loguercio
4 min readFeb 3, 2022
Photo by Dayne Topkin on Unsplash

If you’re showing sensitive data, eg. a wallet amount, or simply when a login form shows the password inserted in clear (think at eye icon..), you have to hide sensitive data when you aren’t in the app.

A lot of apps already do so, either on Android or iOS.

Today we will see how to accomplish this task without using any package and write all the code on our own. Don’t worry, it’s easy.

So, go on and see how to hide the app preview when you switch from one app to another.

Get Started

Now, let’s start coding!

Create a new basic Flutter app. ( I suppose you know how to do that ^^ ).

Android

In Android, it’s super easy.

We only need to update the MainActivity.kt into your android native project adding only one line of code in the onCreate method.

--

--

Carlo Loguercio

I’m Carlo and I’m a passionate Italian coder since 2009. I’m Java native speaker and I’ve never left the JAVA_HOME since I’ve met Dart and Flutter in late 2019.