Ask Your Question
4

Is it possible to show several holidays using table_calendar in Flutter?

asked 2021-07-31 11:00:00 +0000

djk gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-02-05 23:00:00 +0000

scrum gravatar image

Yes, it is possible to show several holidays using the tablecalendar package in Flutter. The package provides the option to define custom event markers for specific dates, which can be used to indicate holidays or any other special dates. Here's an example of how to add multiple holidays to a tablecalendar widget:

TableCalendar(
  // ...other properties
  events: {
    DateTime(2021, 1, 1): ['New Year\'s Day'],
    DateTime(2021, 2, 14): ['Valentine\'s Day'],
    DateTime(2021, 4, 4): ['Easter Sunday'],
    DateTime(2021, 5, 31): ['Memorial Day'],
    // ...add more holidays or events here
  },
  calendarStyle: CalendarStyle(
    // ...other properties
    markersMaxAmount: 1, // to only show one marker per day
  ),
  calendarBuilders: CalendarBuilders(
      // customize the marker for holidays
      markersBuilder: (context, date, events, _) {
        if (events.isNotEmpty) {
          return [
            Positioned(
              bottom: 1,
              child: Icon(
                Icons.event_note,
                size: 15.0,
                color: Colors.blueGrey[800],
              ),
            ),
          ];
        }
        return [];
      }),
);

In this example, we define an events map that maps each holiday date to a list of event names. We then use the markersBuilder property of the CalendarBuilders widget to customize the marker shown for holidays. The markersMaxAmount property is set to 1 to only show one marker per day. Finally, we use the Icon widget to display the holiday marker.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-07-31 11:00:00 +0000

Seen: 1 times

Last updated: Feb 05 '22