Closed bawahakim closed 4 months ago
Hi @bawahakim, Thanks for reaching out. We'd be glad to assist.
Your Flutter app can monitor for foreground/background lifecycle state changes by implementing the WidgetsBindingObserver
interface for your Widget
class declaration in main.dart
:
AppLifecycleState? _state;
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_state = state;
});
}
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
}
You'll then be able to check the _state
inside your backgroundNotificationListener()
as follows:
if (_state == AppLifecycleState.paused || _state == null) {
// in background
}
Please let us know if there's anything else we can help with.
In most notification library, we have a lot of information on the notification meta data. I find this library gives little information on such data.
One importantion information for us is the notification lifecycle on action (click): Foreground, Background, Terminated. It's very useful to manage various states based on when the notification was clicked.