I am using a calendar widget in booking an appointment and would love to save the appointment information in real-time database. Any help is highly appreciated. Below is the sample code:
body: Column(
children: [
TableCalendar(
focusedDay: selectedDay,
firstDay: DateTime(1990),
lastDay: DateTime(2100),
calendarFormat: format,
//changing the date
onFormatChanged: (CalendarFormat _format) {
setState(() {
format = _format;
});
},
startingDayOfWeek: StartingDayOfWeek.sunday,
daysOfWeekVisible: true,
onDaySelected: (DateTime selectDay, focusDay) {
setState(() {
selectedDay = selectDay;
focusedDay = focusDay;
});
print(focusedDay);
},
selectedDayPredicate: (DateTime date) {
return isSameDay(selectedDay, date);
},
eventLoader: _getEventsFromDay,
//Styling the calendar
calendarStyle: CalendarStyle(
isTodayHighlighted: true,
selectedDecoration: BoxDecoration(
color: Colors.deepOrange,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(5.0),
),
selectedTextStyle: const TextStyle(color: Colors.white),
todayDecoration: BoxDecoration(
color: Colors.blue,
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(5.0),
),
defaultDecoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(5.0),
),
weekendDecoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.circular(5.0),
),
),
headerStyle: HeaderStyle(
formatButtonVisible: true,
titleCentered: true,
formatButtonShowsNext: false,
formatButtonDecoration: BoxDecoration(
color: Colors.deepOrange,
borderRadius: BorderRadius.circular(5.0),
),
formatButtonTextStyle: const TextStyle(
color: Colors.white,
),
),
),
..._getEventsFromDay(selectedDay).map(
(Event event) => ListTile(
title: Text(event.title),
),
),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () => showDialog(
context: context,
builder: (context) => AlertDialog(
title: const Text('Add an appointment'),
content: TextFormField(
controller: _appointmentController,
minLines: 2,
maxLines: 5,
),
actions: [
TextButton(
onPressed: () => Navigator.pop(context),
child: const Text(
'Cancel',
),
),
TextButton(
onPressed: () {
if (_appointmentController.text.isEmpty) {
} else {
if (selectedEvents[selectedDay] != null) {
selectedEvents[selectedDay]?.add(
Event(title: _appointmentController.text),
);
} else {
selectedEvents[selectedDay] = [
Event(title: _appointmentController.text),
];
}
}
Navigator.pop(context);
_appointmentController.clear();
setState(() {
});
return;
},
child: const Text(
'Ok',
),
),
],
),
),
label: const Text(
'Add Appointment',
),
icon: const Icon(Icons.add),
),
);
}
Is there a way I can be able to store the appointment date to real-time firebase and use the uid to save the different users' appointment dates in an organized manner?