DateFormat dateFormat = DateFormat('yyyy-MM-dd');
DateTime now = DateTime.now();
CalendarFormat calendarFormat = CalendarFormat.month;
List<String> days = ['_', '월', '화', '수', '목', '금', '토', '일'];
Map<dynamic, List<dynamic>> events = {
'2025-06-10': [
{
'title': 'event1',
},
{
'title': 'event2',
},
],
'2025-06-11': [
{
'title': 'event3',
},
],
};
List<dynamic> getEventsForDay(DateTime day) {
return events[day] ?? [];
}
TableCalendar(
firstDay: DateTime(now.year - 1, now.month, 1),
lastDay: DateTime(now.year + 10, 12, 31),
focusedDay: selectDay,
calendarFormat: calendarFormat,
locale: 'ko-KR',
headerStyle: const HeaderStyle(
titleCentered: true,
formatButtonVisible: false,
),
calendarStyle: CalendarStyle(
selectedDecoration: const BoxDecoration(
color: Color(0xFFA48AFF),
shape: BoxShape.circle,
),
defaultDecoration: const BoxDecoration(
shape: BoxShape.circle,
),
todayDecoration: BoxDecoration(
color: Colors.blueAccent.shade100,
shape: BoxShape.circle,
),
markerDecoration: const BoxDecoration(
color: Color(0xFFA48AFF),
shape: BoxShape.circle,
),
),
selectedDayPredicate: (day) {
return isSameDay(selectDay, day);
},
onDaySelected: (selectedDay, focusedDay) {
setState(() {
selectDay = selectedDay;
now = focusedDay;
})
},
onPageChanged: (focusedDay) {
setState(() {
now = focusedDay;
})
},
calendarBuilders: CalendarBuilders(
dowBuilder: (context, day) {
return Center(
child: Text(days[day.weekday]),
);
},
markerBuilder: (context, day, events) {
if (events.isNotEmpty) {
return const Text('${events.length}개');
}
return null;
},
),
eventLoader: (day) {
final dateFormat = DateFormat('yyyy-MM-dd');
final newDay = dateFormat.format(day);
return getEventsForDay(dateFormat.parse(newDay));
},
)