Showing Event from API to Flutter Carousel Calender

Viewed 491

I want to show a Carousel Calendar and mark present ,absent and leave of a student by using Rest Api. I need to show these events by different color. The event already exists from API.

enter image description here

1 Answers

You have to convert your timestamp data from the API into a DateTime object.

DateTime dateTime = DateTime.parse(timestamp);

And then use the customDayBuilder property to define the appropriate widget with the color that you want.

customDayBuilder: (   /// you can provide your own build function to make custom day containers
        bool isSelectable,
        int index,
        bool isSelectedDay,
        bool isToday,
        bool isPrevMonthDay,
        TextStyle textStyle,
        bool isNextMonthDay,
        bool isThisMonthDay,
        DateTime day,
      ) {
          /// If you return null, [CalendarCarousel] will build container for current [day] with default function.
          /// This way you can build custom containers for specific days only, leaving rest as default.


          if (day.difference(dateTime).inDays == 0) {
            // Do additional checks for status, remarks or for checking
            // whether the day should be marked as absent, present or something else
            return Container(
              decoration: BoxDecoration(
                color: Colors.red // Change this color according to your case.
                shape: BoxShape.circle,
            );
          } else {
            return null; // returning null will build container for current [day] with default function.
          }
      },
Related