summaryrefslogtreecommitdiff
path: root/mobile/lib/routes.dart
diff options
context:
space:
mode:
authoromagdy7 <omar.professional8777@gmail.com>2023-12-23 01:39:59 +0200
committeromagdy7 <omar.professional8777@gmail.com>2023-12-23 01:39:59 +0200
commitfbaae8f461ff085356670d41506cd92180227beb (patch)
treea7a6b9c83f22961c1b4e5cea02841a2f58f81116 /mobile/lib/routes.dart
parent776f680ca58d066e24284b009eb9a28ced03a6ea (diff)
downloadcarpool-fbaae8f461ff085356670d41506cd92180227beb.tar.xz
carpool-fbaae8f461ff085356670d41506cd92180227beb.zip
Final version
Diffstat (limited to 'mobile/lib/routes.dart')
-rw-r--r--mobile/lib/routes.dart131
1 files changed, 111 insertions, 20 deletions
diff --git a/mobile/lib/routes.dart b/mobile/lib/routes.dart
index 5073271..88fb9fb 100644
--- a/mobile/lib/routes.dart
+++ b/mobile/lib/routes.dart
@@ -1,6 +1,7 @@
+import 'package:carpool/drawer.dart';
+import 'package:carpool/ride_request.dart';
import 'package:flutter/material.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
-import 'cart.dart';
import 'package:intl/intl.dart';
// Accessing Firestore instance
@@ -10,11 +11,51 @@ class Route {
final String name;
final String startLocation;
final String endLocation;
+ final String carBrand;
+ final String carModel;
+ final String carColor;
+ final String plateNumber;
+ final String status;
+ final DateTime orderTime;
- Route(
- {required this.name,
- required this.startLocation,
- required this.endLocation});
+ Route({
+ required this.name,
+ required this.startLocation,
+ required this.endLocation,
+ required this.carBrand,
+ required this.carModel,
+ required this.carColor,
+ required this.plateNumber,
+ required this.status,
+ required this.orderTime,
+ });
+}
+
+Color getColorFromString(String color) {
+ switch (color.toLowerCase()) {
+ case 'red':
+ return Colors.red;
+ case 'blue':
+ return Colors.blue;
+ case 'green':
+ return Colors.green;
+ case 'yellow':
+ return Colors.yellow;
+ case 'orange':
+ return Colors.orange;
+ case 'purple':
+ return Colors.purple;
+ case 'pink':
+ return Colors.pink;
+ case 'cyan':
+ return Colors.cyan;
+ case 'silver':
+ return Colors.grey;
+ // You can add more cases for additional colors as needed
+ default:
+ // Return a default color if the input doesn't match any specified colors
+ return Colors.black;
+ }
}
Future<List<Route>> getDataFromFirestore() async {
@@ -24,17 +65,29 @@ Future<List<Route>> getDataFromFirestore() async {
QuerySnapshot querySnapshot = await firestore.collection('Rides').get();
// Loop through the documents in the collection
- querySnapshot.docs.forEach((doc) {
+ querySnapshot.docs
+ .where((element) => element['status'] == 'Unreserved')
+ .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'];
+ String carModel = doc['carModel'];
+ String carBrand = doc['carBrand'];
+ String carColor = doc['carColor'];
+ String plateNumber = doc['plateNumber'];
+ String status = doc['status'];
+ Timestamp orderTime = doc['orderTime'];
routes.add(Route(
- name: name, startLocation: fromLocation, endLocation: toLocation));
+ name: name,
+ startLocation: fromLocation,
+ endLocation: toLocation,
+ carModel: carModel,
+ carBrand: carBrand,
+ carColor: carColor,
+ plateNumber: plateNumber,
+ status: status,
+ orderTime: orderTime.toDate(),
+ ));
});
} catch (e) {
print('Error retrieving data: $e');
@@ -43,7 +96,10 @@ Future<List<Route>> getDataFromFirestore() async {
}
class RoutesPage extends StatefulWidget {
+ const RoutesPage({super.key});
+
@override
+ // ignore: library_private_types_in_public_api
_RoutesPageState createState() => _RoutesPageState();
}
@@ -67,6 +123,7 @@ class _RoutesPageState extends State<RoutesPage> {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Routes')),
+ drawer: const CustomDrawer(),
body: ListView.builder(
itemCount: routes.length,
itemBuilder: (BuildContext context, int index) {
@@ -74,18 +131,21 @@ class _RoutesPageState extends State<RoutesPage> {
return GestureDetector(
onTap: () {
DateTime now = DateTime.now();
- String formattedDateTime =
- DateFormat('EEEE dd/MM/yyyy hh:mm a').format(now);
Ride selectedRide = Ride(
- name: route.name,
- startLocation: route.startLocation,
- endLocation: route.endLocation,
- time: formattedDateTime,
- );
+ name: route.name,
+ startLocation: route.startLocation,
+ endLocation: route.endLocation,
+ carModel: route.carModel,
+ carBrand: route.carBrand,
+ carColor: route.carColor,
+ plateNumber: route.plateNumber,
+ status: route.status,
+ orderTime: route.orderTime);
Navigator.push(
context,
MaterialPageRoute(
- builder: (context) => CartPage(selectedRide: selectedRide),
+ builder: (context) =>
+ RequestRidePage(selectedRide: selectedRide),
),
);
},
@@ -120,6 +180,37 @@ class _RoutesPageState extends State<RoutesPage> {
Flexible(child: Text(route.endLocation)),
],
),
+ Row(
+ children: [
+ Icon(Icons.directions_car,
+ color: getColorFromString(route.carColor)),
+ const SizedBox(width: 4),
+ Text('${route.carBrand} - ${route.carModel}'),
+ ],
+ ),
+ Row(
+ children: [
+ const Icon(Icons.confirmation_number,
+ color: Colors.blue),
+ const SizedBox(width: 4),
+ Text('Plate: ${route.plateNumber}'),
+ ],
+ ),
+ Row(
+ children: [
+ const Icon(Icons.info, color: Colors.blue),
+ const SizedBox(width: 4),
+ Text('Status: ${route.status}'),
+ ],
+ ),
+ Row(
+ children: [
+ const Icon(Icons.schedule, color: Colors.blue),
+ const SizedBox(width: 4),
+ Text(DateFormat('EEEE dd/MM/yyyy hh:mm a')
+ .format(route.orderTime)),
+ ],
+ ),
],
),
leading: const Icon(Icons.directions_car),