我正在开发一款扑扑的积水应用程序。我希望某个特定功能即使在该应用程序被终止的情况下也可以在后台运行。我有一个通知功能。我希望该通知功能即使在应用程序不在后台运行时也可以在后台运行,但我不知道在哪里调用该函数。
这是通知功能:
_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);
}
我每次用户输入摄入量时都调用此函数。在应用程序运行之前,它可以正常工作。但是,如果该应用已关闭或被杀死。这是行不通的。因此,即使应用程序被终止,我应该在哪里调用此函数以使其运行。
我没有任何资源来实现这一目标,而且我还是个初学者。有人可以帮我吗预先感谢。