Skip to content

Commit f97869c

Browse files
committed
MVP complete
1 parent 6806de8 commit f97869c

File tree

6 files changed

+96
-75
lines changed

6 files changed

+96
-75
lines changed

ios/Runner/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import GoogleMaps
1010
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
1111
) -> Bool {
1212
GeneratedPluginRegistrant.register(with: self)
13-
GMSServices.provideAPIKey("APIKEY")
13+
GMSServices.provideAPIKey("API-KEY")
1414
// FirebaseApp.configure()
1515
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
1616
}

lib/screens/account_screen.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ class AccountScreenState extends State<AccountScreen> {
3636
children: [
3737
Padding(
3838
padding: EdgeInsets.only(
39-
left: widthSize * 0.04,
40-
top: heightSize * 0.03,
39+
left: widthSize * 0.08,
40+
top: heightSize * 0.05,
4141
bottom: heightSize * 0.03),
4242
child: Text(
4343
"Account",
@@ -48,7 +48,7 @@ class AccountScreenState extends State<AccountScreen> {
4848
),
4949
Container(
5050
margin:
51-
EdgeInsets.only(left: widthSize * 0.02, right: widthSize * 0.02),
51+
EdgeInsets.only(left: widthSize * 0.06, right: widthSize * 0.05),
5252
height: heightSize * 0.30,
5353
child: ListView.separated(
5454
padding: const EdgeInsets.all(8),
@@ -65,7 +65,7 @@ class AccountScreenState extends State<AccountScreen> {
6565
},
6666
separatorBuilder: (BuildContext context, int index) =>
6767
const Divider(),
68-
))
68+
)),
6969
]);
7070
}
7171
}

lib/screens/driver_screens/map_drive_widget.dart

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,21 @@ Widget MapDriveWidget(FirebaseService _auth, BuildContext context,
3434
fontWeight: FontWeight.bold),
3535
);
3636
} else {
37-
return CircularProgressIndicator(
38-
color: Colors.black,
37+
return Column(
38+
mainAxisAlignment: MainAxisAlignment.spaceAround,
39+
children: [
40+
Text(
41+
"Loading...",
42+
style: TextStyle(
43+
fontSize: 22,
44+
color: Colors.white,
45+
decoration: TextDecoration.none,
46+
fontWeight: FontWeight.bold),
47+
),
48+
CircularProgressIndicator(
49+
color: Colors.black,
50+
)
51+
],
3952
);
4053
}
4154
}),
@@ -75,16 +88,6 @@ Widget MapDriveWidget(FirebaseService _auth, BuildContext context,
7588
},
7689
),
7790
SizedBox(height: heightSize * 0.02),
78-
Text(
79-
"0 Riders",
80-
style: TextStyle(
81-
fontSize: 22,
82-
color: Colors.white,
83-
fontWeight: FontWeight.bold,
84-
decoration: TextDecoration.none,
85-
),
86-
),
87-
SizedBox(height: heightSize * 0.02),
8891
ElevatedButton(
8992
style: ButtonStyle(
9093
foregroundColor: MaterialStateProperty.resolveWith(

lib/screens/home_screen.dart

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -136,36 +136,7 @@ class HomeScreen extends StatelessWidget {
136136
Row(
137137
mainAxisAlignment: MainAxisAlignment.spaceBetween,
138138
children: [
139-
Row(
140-
children: [
141-
Padding(
142-
padding: const EdgeInsets.only(right: 8.0),
143-
child: Icon(Icons.account_circle,
144-
size: heightSize * 0.065),
145-
),
146-
Column(
147-
crossAxisAlignment: CrossAxisAlignment.start,
148-
mainAxisSize: MainAxisSize.min,
149-
children: [
150-
buildText('Rebeka ratry',
151-
TextStyle(fontSize: widthSize * 0.04)),
152-
Padding(padding: const EdgeInsets.all(3)),
153-
buildText('22 Jan 2020',
154-
TextStyle(fontSize: widthSize * 0.04)),
155-
],
156-
),
157-
],
158-
),
159-
Column(
160-
crossAxisAlignment: CrossAxisAlignment.end,
161-
children: [
162-
buildText('+\$1,190.00',
163-
TextStyle(fontSize: widthSize * 0.04)),
164-
Padding(padding: const EdgeInsets.all(3)),
165-
buildText(
166-
'03:25am', TextStyle(fontSize: widthSize * 0.04)),
167-
],
168-
)
139+
Text('No Activity'),
169140
],
170141
),
171142
],

lib/screens/map_screen.dart

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import 'package:carpool_app/screens/driver_screens/map_drive_widget.dart';
1616
import 'package:carpool_app/services/map_metrics_service.dart';
1717
import 'driver_screens/map_drive_widget.dart';
1818
import 'rider_screens/map_new_rider_create_request_widget.dart';
19+
import 'package:progress_indicators/progress_indicators.dart';
1920

2021
class MapScreen extends StatefulWidget {
2122
final String origin;
@@ -196,7 +197,18 @@ class MapScreenState extends State<MapScreen> {
196197

197198
Widget decideWidget(String currentWidgetState, var directions,
198199
double widthSize, double heightSize) {
199-
if (currentWidgetState == "ROUTESCREEN") {
200+
if (currentWidgetState == "RIDESCEENLOADING") {
201+
return Expanded(
202+
child: Container(
203+
height: heightSize * 0.20,
204+
decoration: BoxDecoration(
205+
color: const Color(0xff199EFF),
206+
borderRadius: BorderRadius.all(Radius.circular(25))),
207+
child:
208+
Row(mainAxisAlignment: MainAxisAlignment.center, children: [
209+
MapNewRiderCreateRequestWidget(context, heightSize, "CREATE")
210+
])));
211+
} else if (currentWidgetState == "ROUTESCREEN") {
200212
return MapRouteScreen();
201213
} else if (currentWidgetState == "DRIVESCREEN") {
202214
// for drivers
@@ -215,17 +227,14 @@ class MapScreenState extends State<MapScreen> {
215227
AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>> snapshot) {
216228
Widget child;
217229
if (snapshot.hasError) {
218-
child = const Icon(
219-
Icons.error_outline,
220-
color: Colors.red,
221-
size: 60,
222-
);
230+
child = MapNewRiderFailedRequestWidget(context, heightSize);
223231
} else if (snapshot.hasData) {
224232
if (snapshot.data?.docs.isEmpty ?? true) {
225-
child = MapDriveWidget(_auth, context, directions, heightSize);
233+
child =
234+
MapNewRiderCreateRequestWidget(context, heightSize, "CREATE");
226235
} else {
227-
// child = Text('${snapshot.data!.docs.single.data()}');
228236
String status = snapshot.data?.docs.first.data()["status"];
237+
229238
if (status == "CREATE" || status == "PENDING") {
230239
// STATUS: CREATE OR PENDING
231240
child =
@@ -247,16 +256,15 @@ class MapScreenState extends State<MapScreen> {
247256
child = Column(
248257
mainAxisAlignment: MainAxisAlignment.spaceAround,
249258
children: [
259+
JumpingDotsProgressIndicator(
260+
fontSize: 50.0, color: Colors.white),
250261
Text(
251262
"Loading...",
252263
style: TextStyle(
253264
fontSize: 22,
254265
color: Colors.white,
255266
decoration: TextDecoration.none,
256267
fontWeight: FontWeight.bold),
257-
),
258-
CircularProgressIndicator(
259-
color: Colors.black,
260268
)
261269
],
262270
);
@@ -292,9 +300,20 @@ class MapScreenState extends State<MapScreen> {
292300
if (snapshot.data?.docs.isEmpty ?? true) {
293301
child = MapDriveWidget(_auth, context, directions, heightSize);
294302
} else {
295-
// child = Text('${snapshot.data!.docs.single.data()}');
296303
String status = snapshot.data?.docs.first.data()["status"];
297-
if (status == 'PENDING' || status == 'CREATE') {
304+
305+
double riderLatPoint =
306+
snapshot.data?.docs.first.data()["start_loc_lat"];
307+
double riderLngPoint =
308+
snapshot.data?.docs.first.data()["start_loc_lng"];
309+
310+
double driveLatPoint = directions["start_location"]["lat"];
311+
double driveLngPoint = directions["start_location"]["lng"];
312+
313+
// to only match those riders that are travelling for same origin and destination location as the driver
314+
if ((status == 'PENDING' || status == 'CREATE') &&
315+
(riderLatPoint == driveLatPoint &&
316+
riderLngPoint == driveLngPoint)) {
298317
child = MapNewRiderWidget(context, heightSize,
299318
snapshot.data?.docs.first.data(), directions);
300319
} else if (status == 'ACCEPTED') {
@@ -424,11 +443,13 @@ class MapScreenState extends State<MapScreen> {
424443
.read<MapScreenProvider>()
425444
.setCurrentWidgetState("DRIVESCREEN");
426445
} else {
446+
context
447+
.read<MapScreenProvider>()
448+
.setCurrentWidgetState("RIDESCEENLOADING");
449+
await _auth.newDriveRequest(directions);
427450
context
428451
.read<MapScreenProvider>()
429452
.setCurrentWidgetState("RIDESCEEN");
430-
431-
await _auth.newDriveRequest();
432453
}
433454
},
434455
child: _auth.getCurrentUserRole() == 'driver'

lib/services/firebase_service.dart

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -141,21 +141,25 @@ class FirebaseService {
141141
.update({"isDriving": status});
142142
}
143143

144-
Future<String> newDriveRequest() async {
145-
// created index for this using role and userId based on ascending order
146-
144+
Future<String> newDriveRequest(var directions) async {
147145
var docQuery = await _firestoredb
148146
.collection("users")
149147
.where("role", isEqualTo: 'driver')
150148
.where("userId", isNotEqualTo: _auth.currentUser!.uid)
151149
.where("isDriving", isEqualTo: true)
152150
.get();
153151

152+
var data = await _firestoredb
153+
.collection("users")
154+
.doc(_auth.currentUser!.uid)
155+
.get();
156+
154157
CollectionReference riderRequestcollectionReference = await _firestoredb
155158
.collection("users")
156159
.doc(_auth.currentUser!.uid)
157160
.collection("requests");
158161

162+
// to handle rejeceted request test case
159163
if (docQuery.docs.isEmpty) {
160164
riderRequestcollectionReference
161165
.doc("DUNAVAILABLE")
@@ -173,24 +177,33 @@ class FirebaseService {
173177
}
174178
}
175179

180+
// to use this variables for storing document in both driver and rider requests collection
176181
DocumentReference documentReference = docQuery.docs[0].reference;
177182
String driverDocumentID = documentReference.id;
178183

179184
CollectionReference driverRequestsCollection =
180185
documentReference.collection("requests");
181186
String currentTime = DateTime.now().toString();
182187

188+
// error handling and storing request document in both rider's and driver's requests collection
183189
try {
184190
await driverRequestsCollection.doc(_auth.currentUser!.uid).set({
191+
"riderId": _auth.currentUser!.uid,
192+
"riderName": data["firstName"] + " " + data["lastName"],
185193
"timeStamp": currentTime,
186194
"status": "PENDING",
187-
"riderId": _auth.currentUser!.uid
195+
"distance": directions['distanceInMiles'],
196+
"start_loc_lat": directions["start_location"]["lat"],
197+
"start_loc_lng": directions["start_location"]["lng"]
188198
});
189199

190200
riderRequestcollectionReference.doc(driverDocumentID).set({
201+
"driverId": driverDocumentID,
191202
"timeStamp": currentTime,
192203
"status": "PENDING",
193-
"driverId": driverDocumentID
204+
"distance": directions['distanceInMiles'],
205+
"start_loc_lat": directions["start_location"]["lat"],
206+
"start_loc_lng": directions["start_location"]["lng"]
194207
});
195208

196209
return "PENDING";
@@ -255,16 +268,29 @@ class FirebaseService {
255268
var v1 = uuid.v1();
256269
currentUserRole = role;
257270

258-
Map<String, String> todoList = {
259-
"firstName": firstName,
260-
"lastName": lastName,
261-
"role": role,
262-
"timestamp": timestamp,
263-
"userId": userCredential.user?.uid ?? v1,
264-
};
271+
Map<String, dynamic> userObj;
272+
273+
if (role == 'driver') {
274+
userObj = {
275+
"firstName": firstName,
276+
"lastName": lastName,
277+
"role": role,
278+
"timestamp": timestamp,
279+
"userId": userCredential.user?.uid ?? v1,
280+
};
281+
} else {
282+
userObj = {
283+
"firstName": firstName,
284+
"lastName": lastName,
285+
"isDriving": false,
286+
"role": role,
287+
"timestamp": timestamp,
288+
"userId": userCredential.user?.uid ?? v1,
289+
};
290+
}
265291

266292
documentReference
267-
.set(todoList)
293+
.set(userObj)
268294
.whenComplete(() => print("Data stored successfully"));
269295

270296
Navigator.of(context).pushReplacementNamed("/home");

0 commit comments

Comments
 (0)