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?
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 .
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.
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.
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();
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With