I am developing a water remainder app in a flutter. I want a specific function to run on background even when the app is killed. I have a function that gives notification. I want that notification function to run on background even when the app is not running on the background, but I don't know where to call that function.
This is the notification function:
_scheduleNotify() async {
print("object");
flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin();
var android = new AndroidInitializationSettings('@mipmap/ic_launcher');
var ios = new IOSInitializationSettings();
var initsetting = new InitializationSettings(android, ios);
flutterLocalNotificationsPlugin.initialize(initsetting);
var scheduledNotificationDateTime =
new DateTime.now().add(new Duration(seconds: 5));
var androidPlatformChannelSpecifics = new AndroidNotificationDetails(
'your other channel id',
'your other channel name',
'your other channel description');
var iOSPlatformChannelSpecifics = new IOSNotificationDetails();
NotificationDetails platformChannelSpecifics = new NotificationDetails(
androidPlatformChannelSpecifics, iOSPlatformChannelSpecifics);
await flutterLocalNotificationsPlugin.schedule(
0,
'scheduled title',
'scheduled body',
scheduledNotificationDateTime,
platformChannelSpecifics);
}
I have called this function every time the user gives input of intake. This works fine until the app is running. But if the app is closed or killed. This is not working. So where should I call this function to make this run even when the app is killed?
I didn't get any resources to implement this and I am a beginner in a flutter. Can someone help me with this? Thanks in advance.