我使用了 flutter TableCalendar 插件,我想隐藏过去和下个月的日期选项。我的代码是。
child: TableCalendar(
headerVisible: false,
daysOfWeekVisible: false,
focusedDay: selectedDay,
firstDay: DateTime.now(),
lastDay: DateTime(2050),
startingDayOfWeek: StartingDayOfWeek.monday,
availableGestures: AvailableGestures.none,
daysOfWeekHeight: 20,
),
如您所见,有属性 firstDay 和 lastDay。因此,您可以为该属性分配值,如下所示。
代码:
child: TableCalendar(
headerVisible: false,
daysOfWeekVisible: false,
focusedDay: selectedDay,
firstDay: DateTime.now(),
lastDay: DateTime(DateTime.now().year, now.month + 1, 0).day, // This will return last day of current month
startingDayOfWeek: StartingDayOfWeek.monday,
availableGestures: AvailableGestures.none,
daysOfWeekHeight: 20,
),
因此,通过使用上述代码,用户将无法访问当前日期的前一天和本月底的后一天。希望对你有帮助。如果您还有一些问题,请发表评论。
你可以使用outsideBuilder:
TableCalendar(
...
...
calendarBuilders: CalendarBuilders(
outsideBuilder: (context, day, focusedDay) => Container(),
)
)