Skip to content

Commit

Permalink
fixed appointment bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSena19 committed Oct 14, 2023
1 parent e8b11c9 commit 335a003
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 132 deletions.
1 change: 0 additions & 1 deletion lib/constants/user_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,5 @@ Future<List<DocumentSnapshot>> getAppointments(String name) async {
.collection('appointments')
.where('patient', isEqualTo: name)
.get();
print('Number of documents retrieved: ${querySnapshot.size}');
return querySnapshot.docs;
}
260 changes: 131 additions & 129 deletions lib/screens/apppointment_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@ class AppointmentScreen extends StatefulWidget {
}

class _AppointmentScreenState extends State<AppointmentScreen> {
Alignment _alignment = Alignment.centerLeft;
final String _name = FirebaseAuth.instance.currentUser!.email.toString();
List? _appointments = [];
List<String> filters = ['upcoming', 'completed', 'canceled'];
int index = 0;
FilterStatus status = FilterStatus.upcoming;
String statusString = 'upcoming';
List filteredAppointments = [];

void setFilteredAppointments() {
filteredAppointments = filterAppointments(_appointments!, statusString)!;
}

Future<List<Map<String, dynamic>>?> getAppointmentsData(String name) async {
List<DocumentSnapshot> appointmentSnapshots = await getAppointments(name);
Expand All @@ -29,7 +35,6 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
appointmentSnapshots.map((snapshot) {
return snapshot.data() as Map<String, dynamic>;
}).toList();
print('Appointment Data: $appointmentsData');
return appointmentsData;
}

Expand All @@ -38,9 +43,6 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
List filteredAppointments = appointments.where((appointments) {
return appointments['status'] == status;
}).toList();
print(
'FilteredAppointments: $filteredAppointments',
);
return filteredAppointments;
}
return null;
Expand All @@ -50,28 +52,9 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
List? appointments = await getAppointmentsData(_name);
setState(() {
_appointments = appointments;
print('Appointments: $_appointments');
});
}

Alignment _getAlignmentForIndex(int index) {
switch (index) {
case 0:
{
return Alignment.centerLeft;
}
case 1:
{
return Alignment.center;
}
case 2:
{
return Alignment.centerRight;
}
}
return Alignment.centerLeft;
}

@override
void initState() {
setUserAppointments();
Expand All @@ -85,8 +68,7 @@ class _AppointmentScreenState extends State<AppointmentScreen> {

@override
Widget build(BuildContext context) {
FilterStatus status = FilterStatus.upcoming;

setFilteredAppointments();
return _appointments != null
? Scaffold(
appBar: appbarWidget('Appointments'),
Expand All @@ -108,126 +90,146 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
),
SegmentedButton(
segments: const [
ButtonSegment(value: FilterStatus.upcoming, label: Text('Upcoming')),
ButtonSegment(value: FilterStatus.completed, label: Text('Completed')),
ButtonSegment(value: FilterStatus.canceled, label: Text('Canceled')),
ButtonSegment(
value: FilterStatus.upcoming,
label: Text('Upcoming')),
ButtonSegment(
value: FilterStatus.completed,
label: Text('Completed')),
ButtonSegment(
value: FilterStatus.canceled,
label: Text('Canceled')),
],
selected: <FilterStatus>{status},
onSelectionChanged: (Set<FilterStatus> newSelection){
onSelectionChanged: (Set<FilterStatus> newSelection) {
setState(() {
status = newSelection.first;
if (status == FilterStatus.upcoming) {
statusString = 'upcoming';
} else if (status == FilterStatus.completed) {
statusString = 'completed';
} else if (status == FilterStatus.canceled) {
statusString = 'canceled';
}
filteredAppointments =
filterAppointments(_appointments!, statusString)!;
});
},
),
const SizedBox(
height: 20,
),
Expanded(
child: ListView.builder(
itemCount: _appointments!.length,
itemBuilder: (context, index) {
List? filteredAppointments =
filterAppointments(_appointments!, '$status');
var schedule = filteredAppointments![index];
bool isLastElement =
filteredAppointments.length + 1 == index;
return Card(
elevation: 0,
shape: RoundedRectangleBorder(
side: const BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10),
),
margin: !isLastElement
? const EdgeInsets.only(bottom: 20)
: EdgeInsets.zero,
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
children: [
const CircleAvatar(
backgroundImage:
AssetImage('assets/user.jpg'),
),
const SizedBox(
width: 20,
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Dr. ${schedule['pharmacist']}',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
filteredAppointments.isNotEmpty
? Expanded(
child: ListView.builder(
itemCount: _appointments!.length,
itemBuilder: (context, index) {
var schedule = filteredAppointments[index];
bool isLastElement =
filteredAppointments.length + 1 == index;
return Card(
elevation: 0,
shape: RoundedRectangleBorder(
side: const BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10),
),
margin: !isLastElement
? const EdgeInsets.only(bottom: 20)
: EdgeInsets.zero,
child: Padding(
padding: const EdgeInsets.all(15),
child: Column(
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: [
Row(
children: [
const CircleAvatar(
backgroundImage:
AssetImage('assets/user.jpg'),
),
),
const SizedBox(
height: 10,
),
Text(
schedule['pharmacy'],
style: const TextStyle(
color: Colors.grey,
const SizedBox(
width: 20,
),
),
],
),
],
),
const SizedBox(
height: 15,
),
ScheduleCard(
date: schedule['date'],
time: schedule['time'],
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: OutlinedButton(
onPressed: () {},
child: const Text(
'Cancel',
style: TextStyle(
color: Colors.lightBlueAccent),
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Dr. ${schedule['pharmacist']}',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 10,
),
Text(
schedule['pharmacy'],
style: const TextStyle(
color: Colors.grey,
),
),
],
),
],
),
const SizedBox(
height: 15,
),
),
const SizedBox(
width: 15,
),
Expanded(
child: OutlinedButton(
style: OutlinedButton.styleFrom(
backgroundColor:
Colors.lightBlueAccent),
onPressed: () {},
child: const Text(
'Reschedule',
style: TextStyle(
color: Colors.white,
ScheduleCard(
date: schedule['date'],
time: schedule['time'],
),
const SizedBox(
height: 10,
),
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Expanded(
child: OutlinedButton(
onPressed: () {},
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(
height: 5,
width: 5,
),
],
),
),
Expand Down
6 changes: 5 additions & 1 deletion lib/screens/reset_password_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,16 @@ class _ResetPasswordScreenState extends State<ResetPasswordScreen> {
? 'Enter a valid email'
: null;

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

Future resetPassword() async {
try {
await FirebaseAuth.instance
.sendPasswordResetEmail(email: emailController.text);
} on FirebaseAuthException catch (e) {
showErrorDialog(context, e.toString());
showError('$e');
}
}

Expand Down
6 changes: 5 additions & 1 deletion lib/screens/verify_email_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@ class _VerifyEmailScreenState extends State<VerifyEmailScreen> {
bool isEmailVerified = false;
Timer? timer;

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

Future sendVerificationEmail() async {
try {
final user = FirebaseAuth.instance.currentUser!;
await user.sendEmailVerification();
} catch (e) {
showErrorDialog(context, e.toString());
showError('$e');
}
}

Expand Down

0 comments on commit 335a003

Please sign in to comment.