diff options
| author | omagdy7 <omar.professional8777@gmail.com> | 2023-12-23 01:39:59 +0200 |
|---|---|---|
| committer | omagdy7 <omar.professional8777@gmail.com> | 2023-12-23 01:39:59 +0200 |
| commit | fbaae8f461ff085356670d41506cd92180227beb (patch) | |
| tree | a7a6b9c83f22961c1b4e5cea02841a2f58f81116 /mobile/lib/ride_request.dart | |
| parent | 776f680ca58d066e24284b009eb9a28ced03a6ea (diff) | |
| download | carpool-fbaae8f461ff085356670d41506cd92180227beb.tar.xz carpool-fbaae8f461ff085356670d41506cd92180227beb.zip | |
Final version
Diffstat (limited to 'mobile/lib/ride_request.dart')
| -rw-r--r-- | mobile/lib/ride_request.dart | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/mobile/lib/ride_request.dart b/mobile/lib/ride_request.dart new file mode 100644 index 0000000..454134f --- /dev/null +++ b/mobile/lib/ride_request.dart @@ -0,0 +1,122 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; +import 'package:firebase_auth/firebase_auth.dart'; +import 'package:flutter/material.dart'; + +// Define a Ride class to represent the selected ride +class Ride { + 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; + + Ride({ + 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, + }); +} + +class RequestRidePage extends StatelessWidget { + final Ride selectedRide; + + RequestRidePage({required this.selectedRide}); + + @override + Widget build(BuildContext context) { + return Scaffold( + appBar: AppBar( + title: const Text('Ride Request'), + ), + body: Padding( + padding: const EdgeInsets.all(16.0), + child: Card( + elevation: 5, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(12), + ), + child: Padding( + padding: const EdgeInsets.all(16.0), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + const Text( + 'Selected Ride:', + style: TextStyle(fontSize: 18, fontWeight: FontWeight.bold), + ), + const SizedBox(height: 12), + ListTile( + leading: const Icon(Icons.directions_car, color: Colors.blue), + title: Text(selectedRide.name), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(height: 8), + Row( + children: [ + const Icon(Icons.location_on, color: Colors.blue), + const SizedBox(width: 4), + Text(selectedRide.startLocation), + ], + ), + const SizedBox(height: 4), + Row( + children: [ + const Icon(Icons.arrow_forward, color: Colors.blue), + const SizedBox(width: 4), + Text(selectedRide.endLocation), + ], + ), + ], + ), + ), + const SizedBox(height: 20), + ElevatedButton( + onPressed: () async { + FirebaseFirestore firestore = FirebaseFirestore.instance; + User? user = FirebaseAuth.instance.currentUser; + + if (user != null) { + String userId = user.uid; + print("UserId: ${userId}"); + CollectionReference collection = + firestore.collection('RideRequest'); + + Map<String, dynamic> data = { + 'dropOff': selectedRide.endLocation, + 'pickUp': selectedRide.startLocation, + 'status': "Pending", + 'passengerID': userId, + }; + + try { + // Add a new document with an automatically generated ID + await collection.add(data); + print('Document added successfully!'); + } catch (e) { + print('Error adding document: $e'); + } + } + + print('Processing Requesting Ride'); + }, + child: const Text('Request Ride'), + ), + ], + ), + ), + ), + ), + ); + } +} |
