summaryrefslogtreecommitdiff
path: root/mobile/lib
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-12-21 01:26:51 +0200
committeromagdy7 <omar.professional8777@gmail.com>2023-12-21 01:26:51 +0200
commit7b379914e44583b9b097ed286b669ad244b176a1 (patch)
tree32fc660273161a92a0b9784ac5edd6f2f5eea58c /mobile/lib
parentb84fe9a9c4c18a3f4e957f76ead34403c4316f76 (diff)
downloadcarpool-7b379914e44583b9b097ed286b669ad244b176a1.tar.xz
carpool-7b379914e44583b9b097ed286b669ad244b176a1.zip
Added Firestore support for both the driver app and the rider mobile app
Diffstat (limited to 'mobile/lib')
-rw-r--r--mobile/lib/cart.dart4
-rw-r--r--mobile/lib/routes.dart68
2 files changed, 53 insertions, 19 deletions
diff --git a/mobile/lib/cart.dart b/mobile/lib/cart.dart
index b3d5b0b..109e407 100644
--- a/mobile/lib/cart.dart
+++ b/mobile/lib/cart.dart
@@ -81,9 +81,9 @@ class CartPage extends StatelessWidget {
onPressed: () {
// Implement payment or confirmation logic here
// For now, just print a message
- print('Processing payment/confirmation...');
+ print('Processing Requesting Ride');
},
- child: const Text('Proceed to Payment/Confirm'),
+ child: const Text('Request Ride'),
),
],
),
diff --git a/mobile/lib/routes.dart b/mobile/lib/routes.dart
index de5864c..5073271 100644
--- a/mobile/lib/routes.dart
+++ b/mobile/lib/routes.dart
@@ -1,7 +1,11 @@
import 'package:flutter/material.dart';
+import 'package:cloud_firestore/cloud_firestore.dart';
import 'cart.dart';
import 'package:intl/intl.dart';
+// Accessing Firestore instance
+final FirebaseFirestore firestore = FirebaseFirestore.instance;
+
class Route {
final String name;
final String startLocation;
@@ -13,30 +17,60 @@ class Route {
required this.endLocation});
}
-class RoutesPage extends StatelessWidget {
- final List<Route> dummyRoutes = [
- Route(
- name: 'Morning Ride - Gate 3 to Abdu-Basha',
- startLocation: 'Abassyia',
- endLocation: 'Abdu-Basha Gate-3'),
- Route(
- name: 'Morning Ride - Abdu-Basha to 5th Settlement',
- startLocation: 'Abdu-Basha',
- endLocation: '5th Settlement'),
- Route(
- name: 'Afternoon Ride - Abdu-Basha to Gate 3',
- startLocation: 'Hadayek Elkoba',
- endLocation: 'Abdu-Basha Gate-6'),
- ];
+Future<List<Route>> getDataFromFirestore() async {
+ List<Route> routes = [];
+ try {
+ // Accessing a specific collection ('users' in this case)
+ QuerySnapshot querySnapshot = await firestore.collection('Rides').get();
+
+ // Loop through the documents in the collection
+ querySnapshot.docs.forEach((doc) {
+ String name = doc['driverName'];
+ // String carModel = doc['carModel'];
+ // String carColor = doc['carColor'];
+ // String plateNumber = doc['plateNumber'];
+ // String status = doc['status'];
+ // DateTime orderTime = doc['orderTime'];
+ String fromLocation = doc['fromLocation'];
+ String toLocation = doc['toLocation'];
+ routes.add(Route(
+ name: name, startLocation: fromLocation, endLocation: toLocation));
+ });
+ } catch (e) {
+ print('Error retrieving data: $e');
+ }
+ return routes;
+}
+
+class RoutesPage extends StatefulWidget {
+ @override
+ _RoutesPageState createState() => _RoutesPageState();
+}
+
+class _RoutesPageState extends State<RoutesPage> {
+ List<Route> routes = [];
+
+ @override
+ void initState() {
+ super.initState();
+ fetchRoutesFromFirestore();
+ }
+
+ Future<void> fetchRoutesFromFirestore() async {
+ List<Route> fetchedRoutes = await getDataFromFirestore();
+ setState(() {
+ routes = fetchedRoutes;
+ });
+ }
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Routes')),
body: ListView.builder(
- itemCount: dummyRoutes.length,
+ itemCount: routes.length,
itemBuilder: (BuildContext context, int index) {
- final Route route = dummyRoutes[index];
+ final Route route = routes[index];
return GestureDetector(
onTap: () {
DateTime now = DateTime.now();