radikris / booking_calendar

Flutter package to manage online bookings
MIT License
58 stars 61 forks source link

Dont Display Booked Slots #36

Open hprager07 opened 1 year ago

hprager07 commented 1 year ago

If all the open slots for a day are booked, I dont want the day to be disabled. Is this possible?

hprager07 commented 1 year ago

I actually would prefer to disable a day if there were not appointments available for it. How do I do this?

njonbayou commented 1 year ago

Same, not sure if it is related to the location of the folder, or is it just a missed code snippet somewhere?

njonbayou commented 1 year ago

`final now = DateTime.now();

class Book extends StatefulWidget { const Book({Key? key}) : super(key: key);

@override State createState() => _BookState(); }

class _BookState extends State {

CollectionReference bookings = FirebaseFirestore.instance.collection('book');

CollectionReference getBookingStream({required String placeId}) { return bookings.doc(placeId).collection('booking').withConverter( fromFirestore: (snapshots, ) => DataBook.fromJson(snapshots.data()!), toFirestore: (snapshots, ) => snapshots.toJson(), ); }

Stream? getBookingStreamFirebase( {required DateTime end, required DateTime start}) { return getBookingStream(placeId: 'appointments') .where('bookingStart', isGreaterThanOrEqualTo: start) .where('bookingStart', isLessThanOrEqualTo: end) .snapshots(); }

List convertStreamResultFirebase( {required dynamic streamResult}) { List converted = []; for (var i = 0; i < streamResult.size; i++) { final item = streamResult.docs[i].data(); converted.add(DateTimeRange(start: (item.bookingStart!), end: (item.bookingEnd!))); } return converted; }

Future uploadBookingFirebase( {required BookingService newBooking}) async { await bookings .doc('appointments') .collection('booking') .add(newBooking.toJson()) .then((value) => print("Booking Added")) .catchError((error) => print("Failed to add booking: $error")); }

@override Widget build(BuildContext context) { return Scaffold( body: BookingCalendar( bookedSlotColor: Colors.red, convertStreamResultToDateTimeRanges: convertStreamResultFirebase, uploadBooking: uploadBookingFirebase, getBookingStream: getBookingStreamFirebase, bookingService: BookingService( bookingStart: DateTime.now(), bookingEnd: DateTime.utc(2023, 7, 20, 20, 18, 04), serviceDuration: 30, serviceName: "Meeting" ), ), ); } }`