For some weird reasons I can't get notifications displayed on my flutter app the moment the app is exited.
What I want is that the moment the user exists the app I want to display a notification to tell the user that the app has currently gone into the background.
I am currently using the flutter_local_notifications plugin to achieve this but it isn't working.
Here is what I have tried:
class HomePage extends StatefulWidget {
static const routePath = "/home";
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage > with WidgetsBindingObserver {
@override
initState() {
WidgetsBinding.instance!.addObserver(this);
super.initState();
}
@override
void dispose() {
WidgetsBinding.instance!.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
super.didChangeAppLifecycleState(state);
bool inBackground = state == AppLifecycleState.paused;
if (inBackground) {
displayNotification("AppName","App has gone into the background",null); //This is not displaying at all when the app goes into the background. It only displays when the app is in the foreground. I want it to display the moment the user exits the app.
}
}
Future<void> displayNotification(
String title,
String description,
dynamic payload, {
bool ongoing = false,
}) async {
.....
Any insights to get around this would be really appreciated.