실시간 데이터 소스(예: 스트림을 통해 Firestore와 통합)와 원활하게 통합되도록 설계된 앱 내 온라인 예약 기능을 가능하게 하는 플러터 패키지입니다. 예약 관리, 가용성 표시 및 예약 이벤트를 동적으로 처리할 수 있는 사용자 정의 가능한 캘린더 인터페이스를 제공합니다. 약속 시스템, 이벤트 플래너 또는 서비스 예약 플랫폼과 같은 실시간 업데이트와 상호작용이 필요한 애플리케이션에 적합합니다. 여러 플랫폼을 지원하여 다양한 장치에서 일관된 사용자 경험을 보장합니다.
사용 사례
온라인 예약
이벤트 예약 시스템
서비스 예약 인터페이스
실시간 가용성 추적
실시간 업데이트를 위한 Firestore 통합
주요 기능
스트림 기반 실시간 데이터 지원
크로스 플랫폼 호환성
사용자 정의 가능한 캘린더 UI
동적 예약 이벤트 처리
Firebase Firestore와의 간편한 통합
적합한 대상
예약 앱을 개발하는 개발자
백엔드 데이터에 Firestore를 사용하는 팀
실시간 예약 업데이트가 필요한 애플리케이션
다중 플랫폼 스케줄링 도구
사용자 인터페이스 중심의 예약 인터페이스
고려 사항
스트림 및 비동기 프로그래밍에 대한 지식이 필요합니다
외부 데이터 소스(예: Firestore)에 의존합니다
브랜드 일치를 위해 맞춤 스타일링이 필요할 수 있습니다
성능은 스트림 데이터 부피에 따라 달라집니다
기본 입력 검사 외에 제한된 내장 검증
원본 README
연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.
Booking Calendar
Want to make online bookings in your app? Then luckily you need look no further!
With a total of 4 lines, you get a working online booking system where users can track bookings in real-time.
It calculates the cases where there would be a conflict in the calendar and displays them in different colors.
You can customise your booking calendar with a number of additional parameters.
After you successfully integrated Firebase to your app. How to setup Firebase with Flutter
In this example, we will book sporting slots, using Firebase Firestore.
Here is the model we store in the Firebase:
import'package:cloud_firestore/cloud_firestore.dart';
import'package:json_annotation/json_annotation.dart';
import'package:sport.bp/util/app_util.dart';
part'sport_booking.g.dart';
@JsonSerializable(explicitToJson: true)
classSportBooking{
/// The generated code assumes these values exist in JSON.finalString? userId;
finalString? userName;
finalString? placeId;
finalString? serviceName;
finalint? serviceDuration;
finalint? servicePrice;
//Because we are storing timestamp in Firestore, we need a converter for DateTime/* static DateTime timeStampToDateTime(Timestamp timestamp) {
return DateTime.parse(timestamp.toDate().toString());
}
static Timestamp dateTimeToTimeStamp(DateTime? dateTime) {
return Timestamp.fromDate(dateTime ?? DateTime.now()); //To TimeStamp
}*/@JsonKey(fromJson: AppUtil.timeStampToDateTime, toJson: AppUtil.dateTimeToTimeStamp)
finalDateTime? bookingStart;
@JsonKey(fromJson: AppUtil.timeStampToDateTime, toJson: AppUtil.dateTimeToTimeStamp)
finalDateTime? bookingEnd;
finalString? email;
finalString? phoneNumber;
finalString? placeAddress;
SportBooking(
{this.email,
this.phoneNumber,
this.placeAddress,
this.bookingStart,
this.bookingEnd,
this.placeId,
this.userId,
this.userName,
this.serviceName,
this.serviceDuration,
this.servicePrice});
/// Connect the generated [_$SportBookingFromJson] function to the `fromJson`/// factory.factorySportBooking.fromJson(Map<String, dynamic> json) => _$SportBookingFromJson(json);
/// Connect the generated [_$SportBookingToJson] function to the `toJson` method.Map<String, dynamic> toJson() => _$SportBookingToJson(this);
}
This is how the structure of the data looks like in the Firestore document:
So after the Firebase init, we can access the Firestore collection.
CollectionReference bookings = FirebaseFirestore.instance.collection('bookings');
///This is how can you get the reference to your data from the collection, and serialize the data with the help of the Firestore [withConverter]. This function would be in your repository.CollectionReference<SportBooking> getBookingStream({requiredString placeId}) {
return bookings.doc(placeId).collection('bookings').withConverter<SportBooking>(
fromFirestore: (snapshots, _) => SportBooking.fromJson(snapshots.data()!),
toFirestore: (snapshots, _) => snapshots.toJson(),
);
}
///How you actually get the stream of data from Firestore with the help of the previous function///note that this query filters are for my data structure, you need to adjust it to your solution.Stream<dynamic>? getBookingStreamFirebase(
{requiredDateTime end, requiredDateTime start}) {
returnApiRepository.
.getBookingStream(placeId: 'YOUR_DOC_ID')
.where('bookingStart', isGreaterThanOrEqualTo: start)
.where('bookingStart', isLessThanOrEqualTo: end)
.snapshots(),
}
///After you fetched the data from firestore, we only need to have a list of datetimes from the bookings:List<DateTimeRange> convertStreamResultFirebase(
{requireddynamic streamResult}) {
///here you can parse the streamresult and convert to [List<DateTimeRange>]///Note that this is dynamic, so you need to know what properties are available on your result, in our case the [SportBooking] has bookingStart and bookingEnd propertyList<DateTimeRange> 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;
}
///This is how you upload data to FirestoreFuture<dynamic> uploadBookingFirebase(
{requiredBookingService newBooking}) async {
await bookings
.doc('your id, or autogenerate')
.collection('bookings')
.add(newBooking.toJson())
.then((value) => print("Booking Added"))
.catchError((error) => print("Failed to add booking: $error"));
}
}
/**AFTER YOU HAVE EVERY HELPER FUNCTION YOU CAN PASS THESE TO YOUR BOOKINGCALENDAR */BookingCalendar(
bookingService: mockBookingService,
convertStreamResultToDateTimeRanges: convertStreamResultFirebase,
getBookingStream: getBookingStreamFirebase,
uploadBooking: uploadBookingFirebase,
uploadingWidget: constCircularProgressIndicator(),
//... other customisation properties
),
Additional information
Feel free to add issues, open PR-s and leave comments on the github repository.