flutter app background code example
Example: allow background service in flutter app
class _MyHomePageState extends State<MyHomePage> with WidgetsBindingObserver {
AppLifecycleState _notification;
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_notification = state;
});
}
initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
...
}
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
}