所以我创建了一个简单的通知类,如下所示:
class NamedNotification{
String title;
DateTime scheduledDate;
int id;
String description;
NamedNotification(this.scheduledDate, this.id, this.title, this.description);
}
Run Code Online (Sandbox Code Playgroud)
我使用这个类来跟踪我的通知,并在创建新通知时将它们添加到列表中。我这样做:
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);
},
Run Code Online (Sandbox Code Playgroud)
但是,每当我尝试将我的 namedNotification 添加到列表中时,我都会收到此错误:
The method 'add' was called on null.
Receiver: null
Tried calling: add(Instance of 'NamedNotification')
Run Code Online (Sandbox Code Playgroud)
我想知道解决这个问题的最佳方法是什么。
所以,我在我的应用程序中实现了一个 CupertinoDatePicker,但是当我尝试访问它时,它显示在整个屏幕上,而不仅仅是底部。
这是代码:
onPressed: () {
showCupertinoModalPopup(
context: context,
builder: (BuildContext context) => CupertinoDatePicker(
mode: CupertinoDatePickerMode.dateAndTime,
onDateTimeChanged: (DateTime date) {
_dateTime = date;
}),
);
},
Run Code Online (Sandbox Code Playgroud)
我想知道为什么会这样。参考文档也没有真正的帮助。