Skip to content

Commit

Permalink
updated search screen
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelSena19 committed Oct 13, 2023
1 parent c5f7783 commit 4b5e43f
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 5 deletions.
21 changes: 21 additions & 0 deletions lib/constants/user_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,24 @@ Future<DocumentSnapshot<Map<String, dynamic>>?> getPharmacistInfo(
return null;
}
}

Future<List<String>> getPharmacistNames() async {
List<String> pharmacistNames = [];
try {
CollectionReference pharmacistsCollection =
FirebaseFirestore.instance.collection('pharmacists');

QuerySnapshot pharmacistSnapshot = await pharmacistsCollection.get();

for (QueryDocumentSnapshot document in pharmacistSnapshot.docs) {
Map<String, dynamic> data = document.data() as Map<String, dynamic>;
String name =
data['name'];
pharmacistNames.add(name);
}
} catch (e) {
rethrow;
}

return pharmacistNames;
}
2 changes: 0 additions & 2 deletions lib/screens/pharmacist_details_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:health_watch/constants/push_routes.dart';
import 'package:health_watch/constants/routes.dart';
import 'package:health_watch/constants/user_data.dart';
import 'package:health_watch/utilities/appbar_widget.dart';
import 'package:health_watch/utilities/drawer_widget.dart';

class PharmacistDetailsScreen extends StatefulWidget {
const PharmacistDetailsScreen({Key? key, required this.name})
Expand All @@ -24,7 +23,6 @@ class _PharmacistDetailsScreenState extends State<PharmacistDetailsScreen> {
Widget build(BuildContext context) {
return Scaffold(
appBar: appbarWidget("Pharmacist Details"),
drawer: drawerWidget(context),
body: ListView(
scrollDirection: Axis.vertical,
children: [
Expand Down
98 changes: 95 additions & 3 deletions lib/screens/search_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,36 @@ class _SearchScreenState extends State<SearchScreen> {
child: ListView(
scrollDirection: Axis.vertical,
children: [
SearchAnchor(builder: (context, SearchController controller) {
return SearchBar(
controller: controller,
hintText: 'Search for pharmacists and pharmacies near you',
hintStyle: MaterialStateProperty.all(
const TextStyle(color: Colors.grey)),
elevation: MaterialStateProperty.all(1),
padding: const MaterialStatePropertyAll<EdgeInsets>(
EdgeInsets.symmetric(horizontal: 8)),
onTap: () {
controller.openView();
},
onChanged: (_) {
controller.openView();
},
leading: const Icon(Icons.search),
);
}, suggestionsBuilder: (context, SearchController controller) {
return List<ListTile>.generate(5, (int index) {
final String item = 'pharmacist ${index + 1}';
return ListTile(
title: Text(item),
onTap: () {
setState(() {
controller.closeView(item);
});
},
);
});
}),
const SizedBox(
height: 10,
),
Expand All @@ -37,9 +67,25 @@ class _SearchScreenState extends State<SearchScreen> {
const SizedBox(
height: 40,
),
const Text(
"Top Pharmacists",
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
Row(
children: [
const Text(
"Top Pharmacists",
style: TextStyle(fontSize: 15, fontWeight: FontWeight.bold),
),
Expanded(child: Container()),
TextButton(
onPressed: () {
Navigator.push(context, MaterialPageRoute(builder: (context){
return const SeeMore();
}));
},
child: const Text(
'See More...',
style: TextStyle(color: Colors.lightBlueAccent),
),
),
],
),
const SizedBox(
height: 20,
Expand Down Expand Up @@ -85,3 +131,49 @@ class _SearchScreenState extends State<SearchScreen> {
);
}
}

class SeeMore extends StatelessWidget {
const SeeMore({super.key});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.transparent,
centerTitle: true,
title: const Icon(Icons.local_pharmacy_outlined, color: Colors.lightBlue, size: 30,),
),
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('pharmacists').snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return Text('Error: ${snapshot.error}');
} else if (snapshot.connectionState ==
ConnectionState.waiting) {
return const Center(
child: SizedBox(
height: 10,
width: 10,
child: CircularProgressIndicator(),
),
);
} else {
final pharmacists = snapshot.data!.docs;
return ListView(
children: List.generate(pharmacists.length, (index) {
final pharmacist = pharmacists[index];
return DoctorCard(
name: pharmacist['name'] ?? '',
pharmacy: pharmacist['pharmacy'] ?? '',
rating: pharmacist['rating'] ?? 0.0,
);
}),
);
}
},
),
);
}
}

0 comments on commit 4b5e43f

Please sign in to comment.