How to get unreserved appointments DateTime in specific day?

How to get unreserved appointments DateTime in specific day?


3 Replies

IR Indumathi Ravichandran Syncfusion Team October 12, 2021 03:13 PM UTC

Hi Jhon, 
 
Thank you for contacting Syncfusion support.

 
Regarding Query: How to get unreserved appointments DateTime in specific day? 
 
Based on the shared information, we have checked and your requirement is “Getting the free slots DateTime in the Flutter Calendar”. We have prepared the simple sample for getting the free slots using getVisibleAppointments method. Please find the sample from the following link. 
 
 
Also please find the code snippet for the same. 
 
Code snippet: 
 
Future<void> _showDialog() async { 
  _freeTime.clear(); 
  final List<Appointment> visibleAppointments = 
  _events.getVisibleAppointments(_controller.displayDate!, ''); 
  final List<int> eventsSlotHour = <int>[]; 
  for (int i = 0; i < visibleAppointments.length; i++) { 
    final Appointment app = visibleAppointments[i]; 
    for (int i = app.startTime.hour; i <= app.endTime.hour; i++) { 
      eventsSlotHour.add(i); 
    } 
  } 
  for (int i = _startHour.toInt(); i <= _endHour.toInt(); i++) { 
    if (!eventsSlotHour.contains(i)) { 
      final DateTime freeTime = DateTime(_controller.displayDate!.year, 
          _controller.displayDate!.month, _controller.displayDate!.day, i); 
      _freeTime.add(freeTime); 
    } 
  } 
 
  await showDialog<Widget>( 
    builder: (BuildContext context) => AlertDialog( 
      title: Container( 
        child: Text('Visible dates contains ' + 
            _freeTime.length.toString() + 
            'slots'), 
      ), 
      contentPadding: const EdgeInsets.all(16.0), 
      content: ListView.builder( 
          itemCount: _freeTime.length, 
          itemBuilder: (BuildContext context, int index) { 
            return Container( 
                color: Colors.greenAccent, 
                child: Text(_freeTime.toString())); 
          }), 
      actions: <Widget>[ 
        TextButton( 
            child: const Text('OK'), 
            onPressed: () { 
              Navigator.pop(context); 
            }) 
      ], 
    ), 
    context: context, 
  ); 
} 
 
 
We hope that this helps you. Please let us know if you need further assistance. 
 
Regards, 
Indumathi R 



JG jhon gam replied to Indumathi Ravichandran October 13, 2021 03:38 PM UTC

this code give me wrong free slots DateTime.


the apointments between 00:00 - 10:00 and 12:00 - 24:00

1.PNG


and the results is ...

2.PNG



IR Indumathi Ravichandran Syncfusion Team October 14, 2021 12:09 PM UTC

Hi jhon, 
 
Thank you for the update. 
 
In our last response, we have shared the prototype sample for showing the free slots (slot without appointment) in the calendar by considering a normal appointment, we didn’t consider the spanned appointment in that sample. Now we have prepared the simple sample with considering the spanned appointment and it shows correct free time slots in the calendar. Please find the sample from the following link. 
 
 
We hope that this helps you. Please let us know if you need further assistance. 
 
Regards, 
Indumathi R 


Loader.
Up arrow icon