Flutter 如何在Flatter中实现日历功能,以便在DateTimePickPerform字段中显示当前日期之后的日期直到之后的2天
我希望我的日历在flutter中开始显示从当前日期后一天到之后两天的日期Flutter 如何在Flatter中实现日历功能,以便在DateTimePickPerform字段中显示当前日期之后的日期直到之后的2天,flutter,Flutter,我希望我的日历在flutter中开始显示从当前日期后一天到之后两天的日期 final dateFormat = DateFormat.yMMMMd("en_US"); new DateTimePickerFormField( dateOnly: true, format: dateFormat, validator: (val) { if (val
final dateFormat = DateFormat.yMMMMd("en_US");
new DateTimePickerFormField(
dateOnly: true,
format: dateFormat,
validator: (val) {
if (val != null) {
return null;
} else {
return 'Date field is empty';
}
},
decoration: InputDecoration(labelText: 'Departure Date'),
initialValue: DateTime.now(),
//difference: finalValue.difference(initialValue).inDays,
onSaved: (value) {
debugPrint(value.toString());
},
),
使用
DateTime
类的add
功能:
final dateFormat = DateFormat.yMMMMd("en_US");
new DateTimePickerFormField(
inputType: InputType.date,
format: dateFormat,
validator: (val) {
if (val != null) {
return null;
} else {
return 'Date field is empty';
}
},
decoration: InputDecoration(labelText: 'Departure Date'),
initialDate: DateTime.now().add(Duration(days: 1)),
firstDate: DateTime.now(),
lastDate: DateTime.now().add(Duration(days: 3)),
onSaved: (value) {
debugPrint(value.toString());
},
),
顺便说一句,我将您的代码从使用
dateOnly
参数更改为inputType
,因为前者现在已被弃用,使用它将导致您将来的兼容性问题。你好,易卜拉欣,非常感谢,我实现了您的响应,但日历不再可用,除非我注释掉firstDate:DateTime.now().add(新持续时间(天:1)),当我注释掉firstDate时,firstDate不起作用,但lastDate起作用。firstDate:DateTime.now()没有.add(新持续时间(天:1)),修复了该问题。非常感谢。我正在解决第一个问题,但我很高兴听到你设法解决了。一点也不!