Articles in this section
Category / Section

How to handle the long press action on date selection in the Flutter Calendar

1 min read

In the Flutter Event Calendar, you can handle the long press action on the date selection using onLongPress callback.

void longPressed(CalendarLongPressDetails calendarLongPressDetails) {
  showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          title:Container(child: new Text(" Long pressed")),
          content:Container(child: new Text("Date cell " +DateFormat('dd MMM')
              .format(calendarLongPressDetails.date)
              .toString()+ " has been long pressed")),
          actions: <Widget>[
            new FlatButton(onPressed: (){
              Navigator.of(context).pop();
            }, child: new Text('close'))
          ],
        );
      });
}
 
child: SfCalendar(
  view: CalendarView.month,
  onLongPress: longPressed,
  allowedViews: <CalendarView>[
    CalendarView.day,
    CalendarView.week,
    CalendarView.workWeek,
    CalendarView.month,
    CalendarView.timelineDay,
    CalendarView.timelineWeek,
    CalendarView.timelineWorkWeek,
    CalendarView.timelineMonth,
    CalendarView.schedule
  ],
),

View sample in GitHub

dayview

week view

work week view

            Day                                                    Week                                              Work week

monthview

timeline day

timeline week

              Month                                        Timeline day                                         Timeline week

timeline workweek

timeline month

schedule

          Timeline work week                         Timeline month                                 Schedule

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