skip to Main Content

I am using TableCalendar for showing all data and i am using customWidget for each date.

its showing my customwidget to all dates except current date. i mean to today’s date.

what should i change to my code to show my customwidget for today also.

class CalendarWidget extends StatelessWidget {


  final int month;
  final int year;
  CalendarWidget({Key? key,required this.month,required this.year}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return TableCalendar(
      headerVisible: false,
      availableGestures: AvailableGestures.none,
      focusedDay: DateTime(year,month,1),
      firstDay: DateTime(year,month,1),
      lastDay: DateTime(year,month + 1, 0), // This will return last day of current month
      startingDayOfWeek: StartingDayOfWeek.monday,
      //availableGestures: AvailableGestures.none,
      daysOfWeekHeight: 30,
      rowHeight: 80,
      calendarBuilders: CalendarBuilders(
        defaultBuilder: (context, day, focusedDay) {
          

         return CustomWidget();// this is not showing on current date

        },
      ),
    );
  }
}

enter image description here

2

Answers


  1. You can use todayBuilder

    calendarBuilders: CalendarBuilders(
                          defaultBuilder: (context, day, focusedDay) {
                            return CustomWidget();
                          },
                          todayBuilder: (context, day, focusedDay) {
                            return CustomWidget(); //  this widget will replace Today's cell
                          },
                        ),
    
    Login or Signup to reply.
  2. Use for current day todayBuilder, like this:

    todayBuilder: (context, day, events) {
                return CustomWidget();
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search