Reputation: 185
I'm using flutter dart for developed the for foreground app to keep the app running in background on Android. It's working fine until phone is on lock screen the app is show the notification is still running but the function won't work. Is there any solution for this issues? Thanks
Upvotes: 6
Views: 20173
Reputation: 2714
Basically you can listen to App changes with WidgetBindingsObserver
https://api.flutter.dev/flutter/widgets/WidgetsBindingObserver-class.html
A good article for this (especially lockscreen) can be found here: https://medium.com/@tomalabasteruk/flutter-in-app-lock-screens-f6a17fa02af
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
AppLifecycleState _notification;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_notification = state;
});
}
@override
initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
...
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
}
Upvotes: 1