skip to Main Content

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?

2

Answers


  1. 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),
      );
    
    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search