Flutter 在颤振应用程序中后台运行特定功能

Flutter 在颤振应用程序中后台运行特定功能,flutter,dart,Flutter,Dart,我正在开发一个水剩余物应用程序。我想要一个特定的功能运行在后台,即使当应用程序被杀死。我有一个通知功能。我希望通知功能在后台运行,即使应用程序没有在后台运行,但我不知道在哪里调用该功能 这是通知功能: _scheduleNotify() async { print("object"); flutterLocalNotificationsPlugin = new FlutterLocalNotificationsPlugin(); var android = new AndroidInitiali

我正在开发一个水剩余物应用程序。我想要一个特定的功能运行在后台,即使当应用程序被杀死。我有一个通知功能。我希望通知功能在后台运行,即使应用程序没有在后台运行,但我不知道在哪里调用该功能

这是通知功能:

_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);
}

每次用户输入摄入量时,我都会调用此函数。在应用程序运行之前,这一切正常。但如果应用程序被关闭或关闭。这是行不通的。那么,我应该在哪里调用此函数以使其在应用程序被终止时运行呢


我没有任何资源来实现这一点,我是一个新手。有人能帮我吗?提前感谢。

在后台或应用程序被终止时,请尝试安排通知。希望您正在使用此插件。@AmolG我已尝试安排通知,但现在没有收到任何通知。我在上面的问题中改变了我以前的功能。你能在这里帮我吗。当在后台或应用程序中被杀死时,请尝试安排通知。希望您正在使用此插件。@AmolG我已尝试安排通知,但现在没有收到任何通知。我在上面的问题中改变了我以前的功能。你能帮我吗。