I am trying to set the firstDay in the calendar in TableCalendar to be the first day of the current month. I am not sure how to set it.
Here is how it is formated now:
TableCalendar(
firstDay: DateTime.utc(2022, 11, 01),
lastDay: DateTime.utc(2022, 11, 30),
focusedDay: DateTime.now(),
),
Question how to set the firstDay to the first day of the current month?
CodePudding user response:
according to me the easiest way is to get the last day of date,
lastday = DateTime(date.year, date.month 1, 0);
this will return last day in '2022-11-30 00:00:00.000' and than u can fetch day as integer if u want only day as integer
`` lastday=DateTime(now.year,now.month 1,0).day
CodePudding user response:
var date = DateTime.now();
TableCalendar(
firstDay: DateTime.utc(date.year, date.month, 1),
lastDay: DateTime.utc(date.year, date.month 1, 0),
currentDay: DateTime.utc(date.year, date.month, 1),
focusedDay: DateTime.utc(date.year, date.month, 1),
);