i’m using calendar_ view flutter package to display events on dates, i have read documentation but still confused how to display events on MonthView() Widget
CalendarControllerProvider(
controller: EventController(),
child: MaterialApp(
// Your initialization for material app.
),
)
//reste of code
List<CalendarEventData> events = [
CalendarEventData(
title: "title to display", date: DateTime(2023, 06, 2),
event: "or this event to display")];
MonthView(
controller: EventController(),
// to provide custom UI for month cells.
cellBuilder: (date, events, isToday, isInMonth) {
// Return your widget to display as month cell.
return Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(date.day.toString()),
Text("I want to display here event based on date")
],
);
},
minMonth: DateTime(2020),
maxMonth: DateTime(2023),
initialMonth: DateTime(DateTime.now().year, DateTime.now().month),
onPageChange: (date, pageIndex) => print("$date, $pageIndex"),
onCellTap: (events, date) {
// here we must add event
},
startDay: WeekDays.sunday, // To change the first day of the week.
// This callback will only work if cellBuilder is null.
),
2
Answers
after many tries I got solution with myself maybe someone can find it helpful... the problem was in how to display events in the cells
calendar_view library has an controller (EventController). You can create an instance of this controller:
and using this controller in MonthView
you can add events in this controller: