diff options
Diffstat (limited to 'mobile/lib')
| -rw-r--r-- | mobile/lib/cart.dart | 4 | ||||
| -rw-r--r-- | mobile/lib/routes.dart | 68 |
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(); |
