We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to use navigation drawer for view switching in the Flutter calendar

Platform: Flutter |
Control: SfCalendar |
Published Date: February 15, 2021 |
Last Revised Date: February 16, 2021

In the Flutter Calendar, you can use navigation drawer for view switching by loading controller views in drawer of the Scaffold widget and show the calendar in body region.

In initState(),set the default values for calendar.

CalendarController _controller;
List<String> _items;
 
@override
void initState() {
  super.initState();
  _controller = CalendarController();
  _items = [
    'Day view',
    'Week view',
    'Work week view',
    'Month view',
    'Schedule view',
    'Timeline day',
    'Timeline week',
    'Timeline work week',
    'Timeline month'
  ];
}

Place the ListView.builder in the drawer of the Scaffold widget for view switching.

drawer: Drawer(
  child: ListView.builder(
    itemCount: _items.length,
    itemBuilder: (context, index) {
      return GestureDetector(
          child: ListTile(
            title: Text('${_items[index]}'),
          ),
          onTap: () {
            if (index == 0) {
              _controller.view = CalendarView.day;
              Navigator.pop(context);
            } else if (index == 1) {
              _controller.view = CalendarView.week;
              Navigator.pop(context);
            } else if (index == 2) {
              _controller.view = CalendarView.workWeek;
              Navigator.pop(context);
            } else if (index == 3) {
              _controller.view = CalendarView.month;
              Navigator.pop(context);
            } else if (index == 4) {
              _controller.view = CalendarView.schedule;
              Navigator.pop(context);
            } else if (index == 5) {
              _controller.view = CalendarView.timelineDay;
              Navigator.pop(context);
            } else if (index == 6) {
              _controller.view = CalendarView.timelineWeek;
              Navigator.pop(context);
            } else if (index == 7) {
              _controller.view = CalendarView.timelineWorkWeek;
              Navigator.pop(context);
            } else if (index == 8) {
              _controller.view = CalendarView.timelineMonth;
              Navigator.pop(context);
            }
          });
    },
  ),
),

Place the calendar inside the body of Scaffold widget.

body: SafeArea(
    child: SfCalendar(
  view: CalendarView.month,
  controller: _controller,
  dataSource: _getCalendarDataSource(),
)),

View sample in GitHub

viewswitch gif

 

ADD COMMENT
You must log in to leave a comment

Please sign in to access our KB

This page will automatically be redirected to the sign-in page in 10 seconds.

Up arrow icon

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon