我已经构建了一个待办事项列表应用程序,用户可以在其中根据特定日期和时间安排通知,当应用程序在前台时通知显示没有问题,但是当应用程序在后台或应用程序关闭时,它们不显示up,我不明白为什么,任何原因,谢谢。
- 这是我的代码
late FlutterLocalNotificationsPlugin _localNotificationsPlugin;
List<Task> _list = [];
late MoorController moorController;
@override
void initState() {
super.initState();
moorController = Get.put(MoorController());
createNotification();
//showNotification();
}
void createNotification(){
_localNotificationsPlugin = FlutterLocalNotificationsPlugin();
var initializationSettingsAndroid = const AndroidInitializationSettings("@mipmap/ic_launcher");
var initializationSettingsIOs = const IOSInitializationSettings();
var initSettings = InitializationSettings(android: initializationSettingsAndroid,iOS: initializationSettingsIOs);
_localNotificationsPlugin.initialize(initSettings);
}
void showNotification() async {
var android = const AndroidNotificationDetails(
Utils.CHANNEL_ID,
Utils.CHANNEL_NAME,
channelDescription: Utils.DESCRIPTION,
priority: Priority.high,
importance: Importance.max);
var iOS = const IOSNotificationDetails();
var platform = NotificationDetails(android: android,iOS: iOS);
for (var element in moorController.tasks) {
if(element.date == getCurrentDate() && element.time == getCurrentTime()){
await _localNotificationsPlugin.schedule(
0,element.date,element.time,DateTime.now(),platform, payload : 'Welcome to todo app',androidAllowWhileIdle: true);
//0, element.date,element.time,platform, payload: 'Simple Payload'
}
}
}
- 收货人清单文件
- 权限