Skip to content

Commit

Permalink
fixed null errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSena19 committed Oct 14, 2023
1 parent 54ce1b8 commit dcdafa8
Show file tree
Hide file tree
Showing 4 changed files with 326 additions and 193 deletions.
249 changes: 142 additions & 107 deletions lib/screens/apppointment_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:health_watch/utilities/appbar_widget.dart';
import 'package:health_watch/utilities/appointment_card.dart';
import 'package:health_watch/utilities/drawer_widget.dart';
import 'package:health_watch/utilities/show_error_dialog.dart';
import '../constants/user_data.dart';

enum FilterStatus { upcoming, completed, canceled }
Expand All @@ -25,7 +26,11 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
List filteredAppointments = [];

void setFilteredAppointments() {
filteredAppointments = filterAppointments(_appointments!, statusString)!;
try {
filteredAppointments = filterAppointments(_appointments!, statusString)!;
} catch (e) {
debugPrint('$e');
}
}

Future<List<Map<String, dynamic>>?> getAppointmentsData(String name) async {
Expand Down Expand Up @@ -69,7 +74,7 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
@override
Widget build(BuildContext context) {
setFilteredAppointments();
return _appointments != null
return _appointments!.isNotEmpty
? Scaffold(
appBar: appbarWidget('Appointments'),
drawer: drawerWidget(context),
Expand Down Expand Up @@ -111,8 +116,13 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
} else if (status == FilterStatus.canceled) {
statusString = 'canceled';
}
filteredAppointments =
filterAppointments(_appointments!, statusString)!;
try {
filteredAppointments = filterAppointments(
_appointments!, statusString)!;
} catch (e) {
showErrorDialog(
context, "You don't have any appointments");
}
});
},
),
Expand All @@ -124,105 +134,123 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
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(
width: 20,
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Dr. ${schedule['pharmacist']}',
style: const TextStyle(
color: Colors.black,
fontWeight: FontWeight.bold,
),
),
const SizedBox(
height: 10,
try {
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',
),
Text(
schedule['pharmacy'],
style: const TextStyle(
color: Colors.grey,
),
const SizedBox(
width: 20,
),
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text(
'Dr. ${schedule['pharmacist']}',
style: const TextStyle(
color: Colors.black,
fontWeight:
FontWeight.bold,
),
),
),
],
),
],
),
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(
const SizedBox(
height: 10,
),
Text(
schedule['pharmacy'],
style: const TextStyle(
color: Colors.grey,
),
),
],
),
],
),
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),
.lightBlueAccent,
),
),
),
),
),
const SizedBox(
width: 15,
),
Expanded(
child: OutlinedButton(
style: OutlinedButton.styleFrom(
const SizedBox(
width: 15,
),
Expanded(
child: OutlinedButton(
style:
OutlinedButton.styleFrom(
backgroundColor:
Colors.lightBlueAccent),
onPressed: () {},
child: const Text(
'Reschedule',
style: TextStyle(
color: Colors.white,
Colors.lightBlueAccent,
),
onPressed: () {},
child: const Text(
'Reschedule',
style: TextStyle(
color: Colors.white,
),
),
),
),
),
],
),
],
],
),
],
),
),
);
} on RangeError {
return const SizedBox();
} catch (e) {
return const Center(
child: SizedBox(
height: 10,
width: 10,
child: CircularProgressIndicator(),
),
),
);
);
}
},
),
)
Expand All @@ -235,20 +263,27 @@ class _AppointmentScreenState extends State<AppointmentScreen> {
),
),
)
: Material(
child: SizedBox(
width: 200,
height: 200,
child: Column(
children: [
const Text(
"You don't have any appointments yet",
),
ElevatedButton(
onPressed: () {},
child: const Text('Find Pharmacists'),
),
],
: Scaffold(
appBar: appbarWidget('Appointments'),
body: Center(
child: SizedBox(
width: 500,
height: 200,
child: Column(
children: [
const Text(
"You don't have any appointments yet",
textAlign: TextAlign.center,
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 15),
),
ElevatedButton(
onPressed: () {},
style: ElevatedButton.styleFrom(elevation: 0),
child: const Text('Find Pharmacists'),
),
],
),
),
),
);
Expand Down
6 changes: 6 additions & 0 deletions lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:health_watch/constants/push_routes.dart';
import 'package:health_watch/constants/routes.dart';
import 'package:health_watch/screens/apppointment_screen.dart';
import 'package:health_watch/screens/chat_screen.dart';
import 'package:health_watch/screens/profile_screen.dart';
import 'package:health_watch/screens/search_screen.dart';
Expand All @@ -12,6 +13,7 @@ import 'package:health_watch/utilities/stack_widget.dart';
final List<Widget> _screens = [
const HomeScreen(),
const SearchScreen(),
const AppointmentScreen(),
const ChatScreen(),
const ProfileScreen(),
];
Expand Down Expand Up @@ -52,6 +54,10 @@ class _MainNavigationScreenState extends State<MainNavigationScreen> {
icon: Icon(Icons.search),
label: 'Search',
),
BottomNavigationBarItem(
icon: Icon(Icons.calendar_today_outlined),
label: 'Appointments',
),
BottomNavigationBarItem(
icon: Icon(CupertinoIcons.chat_bubble_text),
label: 'Chats',
Expand Down
Loading

0 comments on commit dcdafa8

Please sign in to comment.