【发布时间】:2020-04-27 16:42:05
【问题描述】:
所以我创建了一个简单的通知类如下:
class NamedNotification{
String title;
DateTime scheduledDate;
int id;
String description;
NamedNotification(this.scheduledDate, this.id, this.title, this.description);
}
我使用这个类来跟踪我的通知,并在创建新通知时将它们添加到列表中。我这样做是这样的:
List<NamedNotification> notifications;
onPressed: () {
setState(() {
NotificationPlugin newNotification = NotificationPlugin();
newNotification.showAtDayAndTimeNotification(_dateTime, id, title, description);
NamedNotification listNotification = NamedNotification(_dateTime, id, title, description);
print(listNotification);
notifications.add(listNotification);
id++;
});
print(id);
Navigator.pop(context);
},
但是,每当我尝试将我的 namedNotification 添加到列表中时,我都会收到以下错误:
The method 'add' was called on null.
Receiver: null
Tried calling: add(Instance of 'NamedNotification')
我想知道解决这个问题的最佳方法是什么。
【问题讨论】: