Articles in this section
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,
    ),
  ),
),

View sample in Github

previous month selected date

current month selected date

next month selected date

 

 

 

 

 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied