How to get the selected dates using selection changed callback in the Flutter Calendar?
In the Flutter Event Calendar, you can display selected date details in an Alert dialog window using the onSelectionChanged callback. This callback is triggered whenever the controller's selected date changes.
In the initState() method, initialize the default values:
final CalendarController _controller = CalendarController(); String _text = '';
Use the onSelectionChanged callback as shown in the following code snippet to display details in an Alert dialog window:
view: CalendarView.day, allowedViews: [ CalendarView.day, CalendarView.week, CalendarView.workWeek, CalendarView.month, CalendarView.timelineDay, CalendarView.timelineWeek, CalendarView.timelineWorkWeek, CalendarView.timelineMonth ], controller: _controller, onSelectionChanged: selectionChanged, ), void selectionChanged(CalendarSelectionDetails details) { if (_controller.view == CalendarView.month || _controller.view == CalendarView.timelineMonth) { _text = DateFormat('dd, MMMM yyyy').format(details.date!).toString(); } else { _text = DateFormat('dd, MMMM yyyy hh:mm a').format(details.date!).toString(); } showDialog( context: context, builder: (BuildContext context) { return AlertDialog( title: Container( child: new Text("Details shown by selection changed callback")), content: Container(child: new Text("You have selected " + '$_text')), actions: <Widget>[ new TextButton( onPressed: () { Navigator.of(context).pop(); }, child: new Text('close')) ], ); }); }
Conclusion
I hope you enjoyed learning about how to get the selected dates using selection changed callback in the Flutter Calendar.
You can refer to our Flutter Calender feature tour page to know about its other groundbreaking feature representations. You can also explore our Flutter Calendar documentation to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!