summaryrefslogtreecommitdiff
path: root/mobile/lib/cart.dart
blob: 7464bb484153dbb3c778bf8794365b98016952b7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
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 CartPage extends StatelessWidget {
  final Ride selectedRide;

  CartPage({required this.selectedRide});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Cart'),
      ),
      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: 4),
                      Row(
                        children: [
                          const Icon(Icons.access_time, color: Colors.blue),
                          const SizedBox(width: 4),
                          // Text(selectedRide.orderTime.toString()),
                        ],
                      ),
                    ],
                  ),
                ),
                const SizedBox(height: 20),
                ElevatedButton(
                  onPressed: () async {
                    FirebaseFirestore firestore = FirebaseFirestore.instance;
                    User? user = FirebaseAuth.instance.currentUser;

                    if (user != null) {
                      String userId = user.uid;
                      CollectionReference collection =
                          firestore.collection('RideRequest');

                      Map<String, dynamic> data = {
                        'dropOff': selectedRide.endLocation,
                        'pickUp': selectedRide.startLocation,
                        'status': "Pending",
                        'cost': "50",
                        'passengerID': userId,
                      };

                      try {
                        await collection.add(data);
                        print('Document added successfully!');
                      } catch (e) {
                        print('Error adding document: $e');
                      }
                    }

                    print('Processing Requesting Ride');
                  },
                  child: const Text('Request Ride'),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}