How to pass dynamic backgroundColor to monthCellBuilder?

From the example given in documentation. I cannot find the function _getMonthCellBackgroundColor(details.date). So I don't know how to exactly pass backgroundColor dynamically.


1 Reply

IR Indumathi Ravichandran Syncfusion Team September 22, 2022 07:23 AM UTC

Hi Rocky,


Based on the shared information, we have checked and your requirement is “Dynamically update the background color for month cells using monthCellBuilder in SfDatRangePicker”. Based on the requirement you can dynamically set the background color for the month cell. We have attached the sample code snippet for the same.


Code snippet:


Color _getMonthCellBackgroundColor(DateTime date) {

 

  if (date.month.isEven) {

 

    if (date.day % 6 == 0) {

 

      return Colors.lightGreen;

 

    } else if (date.day % 5 == 0) {

 

      return Colors.lightGreenAccent;

 

    } else if (date.day % 8 == 0 || date.day % 4 == 0) {

 

      return Colors.limeAccent;

 

    } else if (date.day % 9 == 0 || date.day % 3 == 0) {

 

      return Colors.lime;

 

    } else {

 

      return Colors.green;

 

    }

 

  } else {

 

    if (date.day % 6 == 0) {

 

      return Colors.green;

 

    } else if (date.day % 5 == 0) {

 

      return Colors.lime;

 

    } else if (date.day % 8 == 0 || date.day % 4 == 0) {

 

      return Colors.lightGreenAccent;

 

    } else if (date.day % 9 == 0 || date.day % 3 == 0) {

 

      return Colors.green;

 

    } else {

 

      return Colors.lightGreen;

 

    }

 

  }

 

}

 


Also we have a KB documentations for monthCellBuilder. Please find the documentations from the following link.


KB links:

https://www.syncfusion.com/kb/12210/how-to-customize-the-month-cell-based-on-the-appointment-using-builder-in-the-flutter

https://www.syncfusion.com/kb/12306/how-to-customize-the-month-cell-with-appointment-count-in-the-flutter-calendar


We hope that this helps you. Please let us know if you need further assistance.


Regards,

Indumathi R


Loader.
Up arrow icon