如何在 flutter tablecalendar 中隐藏过去和下个月的日期

问题描述 投票:0回答:2

我使用了 flutter TableCalendar 插件,我想隐藏过去和下个月的日期选项。我的代码是。

             child: TableCalendar(
                  headerVisible: false,
                  daysOfWeekVisible: false,
                  focusedDay: selectedDay,
                  firstDay: DateTime.now(),
                  lastDay: DateTime(2050),
                  startingDayOfWeek: StartingDayOfWeek.monday,
                  availableGestures: AvailableGestures.none,
                  daysOfWeekHeight: 20,
            ),
flutter flutter-layout flutter-dependencies
2个回答
0
投票

如您所见,有属性 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,
            ),

因此,通过使用上述代码,用户将无法访问当前日期的前一天和本月底的后一天。希望对你有帮助。如果您还有一些问题,请发表评论。


0
投票

你可以使用outsideBuilder:

TableCalendar(
...
...
 calendarBuilders: CalendarBuilders(
       outsideBuilder: (context, day, focusedDay) => Container(),
 )
)
© www.soinside.com 2019 - 2024. All rights reserved.