Articles in this section
Category / Section

How to get the appointments between the given start and end date in the Flutter Calendar

1 min read

In the Flutter Event Calendar, the total appointments in the visible dates are achieved by using getVisibleAppointments method.

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

List<Meeting>? _appointments;
List<Appointment>? _visibleAppointments = <Appointment>[];
List<String> _subjectCollection = <String>[];
late _MeetingDataSource _events;
List<Color> _colorCollection = <Color>[];
 
@override
void initState() {
  _appointments = _addAppointment();
  _events = _MeetingDataSource(_appointments!);
 
  super.initState();
}

Use the getVisibleAppointments method in the onViewChanged callback.

void viewChanged(ViewChangedDetails viewChangedDetails) {
  List<DateTime> _date = viewChangedDetails.visibleDates;
  _visibleAppointments =
      _events!.getVisibleAppointments(_date[0], '', _date[_date.length - 1]);
}

Using the onPressed callback of the button, show the appointment details in the alert window.

RaisedButton(
  child: Text('Get visible appointments'),
  onPressed: _showDialog,
),
 
_showDialog() async {
  await showDialog(
    builder: (context) => new AlertDialog(
      title: Container(
        child: Text("Visible dates contains " +
            _visibleAppointments!.length.toString() +
            " appointments"),
      ),
      contentPadding: const EdgeInsets.all(16.0),
      content: ListView.builder(
          itemCount: _visibleAppointments!.length,
          itemBuilder: (BuildContext context, int index) {
            return Container(
                color: _visibleAppointments![index].color,
                child: Text(_visibleAppointments![index].subject));
          }),
      actions: <Widget>[
        new FlatButton(
            child: const Text('OK'),
            onPressed: () {
              Navigator.pop(context);
            })
      ],
    ),
    context: context,
  );
}

View sample in GitHub

Flutter calendar visible appointments

 

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