Skip to content

Commit

Permalink
ui updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSena19 committed Jan 20, 2024
1 parent afec3ef commit b46ccda
Show file tree
Hide file tree
Showing 6 changed files with 202 additions and 91 deletions.
3 changes: 1 addition & 2 deletions lib/providers/appointment_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class AppointmentProvider with ChangeNotifier {
}

Future<void> rescheduleAppointment(
AppointmentModel appointmentModel, DateTime date, String time) async {
AppointmentModel appointmentModel, DateTime date) async {
try {
final appointmentRef =
FirebaseFirestore.instance.collection('appointments');
Expand All @@ -84,7 +84,6 @@ class AppointmentProvider with ChangeNotifier {
final appointmentDoc = querySnapshot.docs.first;
await appointmentDoc.reference.update({
'date': date,
'time': time,
});
notifyListeners();
getUserAppointments(appointmentModel.patient);
Expand Down
158 changes: 120 additions & 38 deletions lib/screens/apppointment_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,33 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
late AppointmentProvider appointmentProvider;
List<AppointmentModel> appointments = [];

Future<DateTime?> pickDate() {
return showDatePicker(
context: context,
initialDate: DateTime.now(),
firstDate: DateTime.now(),
lastDate: DateTime.utc(2025),
);
}

Future<TimeOfDay?> pickTime() {
return showTimePicker(
context: context,
initialTime: TimeOfDay(
hour: TimeOfDay.now().hour,
minute: TimeOfDay.now().minute,
),
);
}

void showError(String error) {
showErrorDialog(context, error);
}

void push(String route) {
pushRoute(context, route);
}

@override
void initState() {
super.initState();
Expand Down Expand Up @@ -180,46 +207,101 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Expanded(
child: OutlinedButton(
onPressed: () {
appointmentProvider.updateStatus(schedule, 'canceled');
},
child: const Text(
'Cancel',
style: TextStyle(
color: Colors
.lightBlueAccent,
schedule.status == 'upcoming'
? Row(
mainAxisAlignment:
MainAxisAlignment
.spaceBetween,
children: [
Expanded(
child: OutlinedButton(
onPressed: () {
appointmentProvider
.updateStatus(
schedule,
'canceled');
ScaffoldMessenger
.of(context)
.showSnackBar(
const SnackBar(
content: Text(
'The appointment has been canceled',
),
),
);
push(homescreenRoute);
},
child: const Text(
'Cancel',
style: TextStyle(
color: Colors
.lightBlueAccent,
),
),
),
),
),
),
),
const SizedBox(
width: 15,
),
Expanded(
child: OutlinedButton(
style: OutlinedButton
.styleFrom(
backgroundColor: Colors
.lightBlueAccent,
),
onPressed: () {},
child: const Text(
'Reschedule',
style: TextStyle(
color: Colors.white,
const SizedBox(
width: 15,
),
),
),
),
],
),
Expanded(
child: OutlinedButton(
style:
OutlinedButton
.styleFrom(
backgroundColor:
Colors
.lightBlueAccent,
),
onPressed:
() async {
final date =
await pickDate();
if (date ==
null) {
showError(
'Please enter a date');
} else {
final time =
await pickTime();
if (time ==
null) {
showError(
'Please enter a time');
} else {
DateTime dateTime = DateTime(
date.year,
date.month,
date.day,
time.hour,
time.minute);
appointmentProvider
.rescheduleAppointment(
schedule,
dateTime);
ScaffoldMessenger.of(
context)
.showSnackBar(
SnackBar(
content: Text(
'Your appointment has been scheduled for $date at $time'),
),
);
push(homescreenRoute);
}
}
},
child: const Text(
'Reschedule',
style: TextStyle(
color: Colors
.white,
),
),
),
),
],
)
: const SizedBox(height: 5)
],
),
),
Expand Down
72 changes: 50 additions & 22 deletions lib/screens/calendar_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,67 @@ class CalendarScreen extends StatefulWidget {
class _CalendarScreenState extends State<CalendarScreen> {
final email = FirebaseAuth.instance.currentUser!.email.toString();
List<AppointmentModel> _appointments = [];
Map<DateTime, List<String>> _events = {};
final ValueNotifier<Map<DateTime, List<String>>> _events = ValueNotifier({});
DateTime? _selectedDay = DateTime.now();
DateTime _focusedDay = DateTime.now();

List<dynamic> _getAppointmentsForDay(){
List<String> appointments = _events.value[_selectedDay] ?? [];
print('Appointments for $_selectedDay: $appointments');
return appointments;
}

void _onDaySelected(DateTime selectedDay, DateTime focusDay){
if(!isSameDay(_selectedDay, selectedDay)){
setState(() {
_selectedDay = selectedDay;
_focusedDay = focusDay;
});
}
}

Future<void> loadEvents() async {
final appointmentProvider = Provider.of<AppointmentProvider>(context, listen: false);
await appointmentProvider.getUserAppointments(email);
_appointments = appointmentProvider.appointments;
Map<DateTime, List<String>> events = {};
for (var appointment in _appointments) {
DateTime date = appointment.date;
events[date] ??= [];
events[date] = ['Dr. ${appointment.pharmacist}'];
}
_events.value = events;
}

@override
Widget build(BuildContext context) {
final appointmentProvider =
Provider.of<AppointmentProvider>(context, listen: false);
return Scaffold(
appBar: appbarWidget('Calendar', Colors.transparent),
drawer: drawerWidget(context),
body: FutureBuilder(
future: appointmentProvider.getUserAppointments(email),
future: loadEvents(),
builder: (context, snapshot) {
if (snapshot.hasError) {
showErrorDialog(context, '${snapshot.error}');
} else if (snapshot.connectionState == ConnectionState.waiting) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const SizedBox();
} else if (snapshot.hasError) {
showErrorDialog(context, '${snapshot.error}');
}
_appointments = appointmentProvider.appointments;
print(_appointments);
_events = {};
for (var appointment in _appointments) {
DateTime date = appointment.date;
_events[date] ??= [];
_events[date] = ['Dr. ${appointment.pharmacist}'];
}
print(_events);
print('Appointments: $_appointments');
print('Events: ${_events.value}');
return ListView(
children: [
TableCalendar(
focusedDay: DateTime.now(),
firstDay: DateTime.now(),
lastDay: DateTime.utc(2030),
eventLoader: (date) => _events[date] ?? [],
ValueListenableBuilder(
valueListenable: _events,
builder: (context, _, __) {
return TableCalendar(
focusedDay: _focusedDay,
onDaySelected: _onDaySelected,
firstDay: DateTime.now(),
lastDay: DateTime.utc(2030),
selectedDayPredicate: (day) => isSameDay(_selectedDay, day),
eventLoader: (day) => _getAppointmentsForDay(),
);
},
)
],
);
Expand All @@ -67,4 +95,4 @@ class _CalendarScreenState extends State<CalendarScreen> {
),
);
}
}
}
37 changes: 19 additions & 18 deletions lib/screens/search_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import '../utilities/appbar_widget.dart';
import '../utilities/appointment_card.dart';
import '../utilities/doctor_card.dart';
import '../utilities/drawer_widget.dart';
import 'package:table_calendar/table_calendar.dart';

class SearchScreen extends StatefulWidget {
const SearchScreen({super.key});
Expand All @@ -36,16 +37,6 @@ class _SearchScreenState extends State<SearchScreen> {
List<PharmacistModel> t5Pharmacists = pharmacistProvider.t5Pharmacists;
final appointmentProvider =
Provider.of<AppointmentProvider>(context, listen: false);
List<AppointmentModel> appointments = appointmentProvider.appointments;
List<AppointmentModel> todayAppointments = [];
for (AppointmentModel appointmentModel in appointments) {
if (appointmentModel.date
.isAtSameMomentAs(DateTime(now.year, now.month, now.day, 0, 0, 0))) {
todayAppointments.add(appointmentModel);
} else {
continue;
}
}
return Scaffold(
appBar: appbarWidget('Search', Colors.transparent),
drawer: drawerWidget(context),
Expand Down Expand Up @@ -102,8 +93,20 @@ class _SearchScreenState extends State<SearchScreen> {
} else if (snapshot.hasError) {
showErrorDialog(context, '${snapshot.error}');
}
List<AppointmentModel> appointments =
appointmentProvider.appointments;
List<AppointmentModel> todayAppointments = [];
for (AppointmentModel appointmentModel in appointments) {
if (isSameDay(appointmentModel.date, DateTime.now()) &&
appointmentModel.status == 'upcoming') {
todayAppointments.add(appointmentModel);
} else {
continue;
}
}
return todayAppointments.isNotEmpty
? Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: todayAppointments.map((appointment) {
return AppointmentCard(
appointment: appointment,
Expand Down Expand Up @@ -149,11 +152,10 @@ class _SearchScreenState extends State<SearchScreen> {
),
FutureBuilder(
future: pharmacistProvider.getT5Pharmacists(),
builder: (context, snapshot){
if(snapshot.connectionState == ConnectionState.waiting){
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const SizedBox();
}
else if(snapshot.hasError){
} else if (snapshot.hasError) {
showErrorDialog(context, '${snapshot.error}');
}
return Column(
Expand Down Expand Up @@ -194,11 +196,10 @@ class SeeMore extends StatelessWidget {
),
body: FutureBuilder(
future: pharmacistProvider.getPharmacists(),
builder: (context, snapshot){
if(snapshot.connectionState == ConnectionState.waiting){
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const SizedBox();
}
else if(snapshot.hasError){
} else if (snapshot.hasError) {
showErrorDialog(context, '${snapshot.error}');
}
return ListView(
Expand Down
Loading

0 comments on commit b46ccda

Please sign in to comment.