im试图使用我在网上找到的日期范围选择器包,但在初次启动时一直收到这个错误
这是我的代码
onTap: () async {
final List<DateTime> picked = await DateRagePicker.showDatePicker(
context: context,
initialFirstDate: new DateTime.now(),
initialLastDate: (new DateTime.now()).add(new Duration(days: 7)),
firstDate: new DateTime(2015),
lastDate: new DateTime(2020)
);
if (picked != null && picked.length == 2) {
print(picked);
}
print("Tapped on container");
}
错误:
Failed assertion: line 1280 pos 10: '!initialLastDate.isAfter(lastDate)': initialDate must be on or before lastDate)
断言说initialLastDate
在lastDate
之后。这是不可能的。DateTime(2020)
在2020年初创建DateTime
。在撰写本文时,我们已经远远超过了这个日期。将lastDate
更改为initialLastDate
之后。
final List<DateTime> picked = await DateRagePicker.showDatePicker(
context: context,
initialFirstDate: new DateTime.now(),
initialLastDate: (new DateTime.now()).add(new Duration(days: 7)),
firstDate: new DateTime(2015),
lastDate: new DateTime(2021)//Cannot be 2020
);