Articles in this section
Category / Section

How to show a particular week in a day view of Flutter Calendar?

1 min read

In the Flutter Event Calendar, you can display a specific week in day view by utilizing the minDate and maxDate properties of the calendar.

In the `initState()` method, set the default values:

DateTime? _minDate, _maxDate, _firstDate, _lastDate;
final CalendarController?  _controller = CalendarController();

Using the onViewChanged callback of the Flutter calendar to retrieve the first and last visible dates:

void viewChanged(ViewChangedDetails viewChangedDetails) {
  if (_controller!.view == CalendarView.week) {
    _firstDate = viewChangedDetails.visibleDates[0];
    _lastDate = viewChangedDetails
        .visibleDates[viewChangedDetails.visibleDates.length - 1];
  }
}

If the calendar view is day,  assign _firstDate, _lastDate to _minDate and _maxDate.

child: SfCalendar(
  view: CalendarView.week,
  controller: _controller,
  minDate: _minDate,
  maxDate: _maxDate,
  onViewChanged: viewChanged,
),
appBar: AppBar(
  actions: [
    FlatButton(
      onPressed: () {
        setState(() {
          _controller!.view = CalendarView.day;
          _minDate = _firstDate;
          _maxDate = _lastDate;
        });
      },
      child: Text("Day"),
    ),
    FlatButton(padding: const EdgeInsets.only(left: 10),
      onPressed: () {
        setState(() {
          _controller!.view = CalendarView.week;
          _minDate = DateTime(01, 01, 01, 01, 0, 0);
          _maxDate = DateTime(9999, 12, 31, 01, 0, 0);
        });
      },
      child: Text("Week"),
    ),
  ],
),

View the GitHub sample here

week days gif

 

Conclusion

I hope you enjoyed learning about how to show a particular week in a day view of Flutter Calendar.

You can refer to our Flutter Calendar feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our  Flutter Calendar example 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 forumsDirect-Trac, or feedback portal. We are always happy to assist you!


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