Category / Section
How to show the appointment in agenda view using the programmatic date selection in the Flutter Calendar
1 min read
In Flutter Date Range Picker, you can programmatically select the date and show the appointment in agenda view using the `selectedDate` property of `CalendarController`.
STEP 1: In `onViewChanged` callback using the `SelectedDate` property of the `CalendarController`, you can show the appointments of the selected date in agenda view and you can programmatically set the `selectedDate` for all months.
void viewChanged(ViewChangedDetails viewChangedDetails) { SchedulerBinding.instance!.addPostFrameCallback((duration) { var midDate = (viewChangedDetails .visibleDates[viewChangedDetails.visibleDates.length ~/ 2]); if (midDate.month == DateTime .now() .month) _calendarController.selectedDate = DateTime.now(); else { _calendarController.selectedDate = DateTime( midDate.year, midDate.month, 01, 9, 0, 0, ); } }); }
STEP 2: Place the calendar inside the body of the Scaffold widget.
home: Scaffold( body: SafeArea( child: SfCalendar( view: CalendarView.month, controller: _calendarController, monthViewSettings: MonthViewSettings(showAgenda: true), dataSource: getCalendarDataSource(), onViewChanged: viewChanged, ), ), ),
|
|
|