Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter - How to hide or change widget as seen in Recent Apps overview

I'm developing a Flutter application that deals with cryptocurrency (a wallet). Some people have requested that the app takes some measures to hide their balance, etc.

The one thing I can't figure out, however, is hiding information from the recent apps menu (like secure window mode on Android, or simply changing the interface so balance isn't visible.)

I added a WidgetsBindingObserver to my main widget and tried something like:

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
  switch (state) {
    case AppLifecycleState.paused:
      setState(() {
          _hideBalance = true;
      });
      super.didChangeAppLifecycleState(state);
      break;
    case AppLifecycleState.resumed:
      setState(() {
          _hideBalance = false;
      });
      super.didChangeAppLifecycleState(state);
      break;
    default:
      super.didChangeAppLifecycleState(state);
      break;
  }
}

@override
void initState() {
   super.initState();
   WidgetsBinding.instance.addObserver(this);
}

@override
void dispose() {
   WidgetsBinding.instance.removeObserver(this);
   super.dispose();
}

@override
Widget build(BuildContext context) {
    return _hideBalance ? SizedBox() : Text("$12,234");
}

However, this has no effect on the recent apps which appears to be an exact snapshot from the moment the home button was pressed (on my OnePlus 6T at least). E.g. - I can still see the balance in the recent apps/app switcher overview.

Is there a way to do this with flutter?

like image 942
bbedward Avatar asked Jan 29 '19 16:01

bbedward


People also ask

How do you change the visibility of a widget in Flutter?

In Flutter, it tends to be done effectively utilizing Visibility a widget. The widget you need to show or hide must be the child of Visibility widget. In the constructor, pass visibility alternative whose value is a boolean and is put away as the state. Then, at that point, update the value to show or hide the child .

How do you lose visibility in Flutter?

In flutter 1.5 and Dart 2.3 for visibility gone, You can set the visibility by using an if statement within the collection without having to make use of containers. That is so much better then options available in previous flutter/dart version.

What are the visibility widgets in Flutter?

Flutter Visibility Widget Visibility is a widget that is useful to show or hide other widgets in flutter. We have to wrap the widget we want to show or hide inside the visibility widget as a child. This widget has a property called visible which controls the state (visible or invisible) of the child.


1 Answers

Are you saying this function is not called? If yes, you need to add the following,

@override
void initState() {
   super.initState();
   WidgetsBinding.instance.addObserver(this);
}

@override
void dispose() {
   WidgetsBinding.instance.removeObserver(this);
   super.dispose();
}
like image 67
user1111 Avatar answered Nov 15 '22 09:11

user1111