Skip to content

Commit d0f6d8a

Browse files
committed
Merge branch 'master' of https://github.com/MnCSSJ4x/carpool
2 parents a4447bb + 7c2a3cb commit d0f6d8a

File tree

4 files changed

+142
-138
lines changed

4 files changed

+142
-138
lines changed

lib/bookingdetails.dart

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
1+
import 'package:carpool/user.dart';
12
import 'package:flutter/material.dart';
23

4+
import 'LoginForm.dart';
5+
36
class BookingDetails extends StatelessWidget {
47
late List<Widget> widgetlist;
58

6-
BookingDetails(this.date, this.starttime, this.endtime, {Key? key})
7-
: super(key: key) {
9+
BookingDetails(this.date, this.starttime, this.endtime, {Key? key, BookingRecord? br}) : super(key: key) {
10+
brs = LoginForm.u.getBookingMatching(br!);
811
widgetlist = [
912
const ListTile(
1013
title: Center(
1114
child: Text(
1215
"Details",
13-
style: TextStyle(
14-
color: Colors.blue,
15-
fontFamily: 'Helvetica',
16-
fontSize: 22,
17-
fontWeight: FontWeight.bold),
16+
style: TextStyle(color: Colors.blue, fontFamily: 'Helvetica', fontSize: 22, fontWeight: FontWeight.bold),
1817
),
1918
),
2019
tileColor: Colors.black,
@@ -27,8 +26,7 @@ class BookingDetails extends StatelessWidget {
2726
),
2827
title: Text(
2928
"Date: $date",
30-
style: const TextStyle(
31-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
29+
style: const TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
3230
),
3331
tileColor: Colors.black,
3432
),
@@ -40,20 +38,15 @@ class BookingDetails extends StatelessWidget {
4038
),
4139
title: Text(
4240
"Time Slot: $starttime Hours to $endtime Hours",
43-
style: const TextStyle(
44-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
41+
style: const TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
4542
),
4643
tileColor: Colors.black,
4744
),
4845
const ListTile(
4946
title: Center(
5047
child: Text(
5148
"Available Carpools",
52-
style: TextStyle(
53-
color: Colors.blue,
54-
fontFamily: 'Helvetica',
55-
fontSize: 22,
56-
fontWeight: FontWeight.bold),
49+
style: TextStyle(color: Colors.blue, fontFamily: 'Helvetica', fontSize: 22, fontWeight: FontWeight.bold),
5750
),
5851
),
5952
tileColor: Colors.black,
@@ -64,16 +57,10 @@ class BookingDetails extends StatelessWidget {
6457
final String date;
6558
final String starttime;
6659
final String endtime;
67-
List<String> carpools = [
68-
"Ishaan Jalan",
69-
"Rudransh Dixit",
70-
"hewwo",
71-
"manda",
72-
"ramesh",
73-
"mukesh",
74-
"sukesh",
75-
"nilesh"
76-
];
60+
late Future<List<BookingRecord>> brs;
61+
// late List<BookingRecord> brs;
62+
List<String> carpools = ["Ishaan Jalan", "Rudransh Dixit", "hewwo", "manda", "ramesh", "mukesh", "sukesh", "nilesh"];
63+
// TODO: add getBookingData..
7764

7865
@override
7966
Widget build(BuildContext context) {
@@ -149,6 +136,7 @@ class BookingDetails extends StatelessWidget {
149136
//DB deletion strategy same as home.dart
150137
Navigator.pop(context);
151138
Navigator.pop(context);
139+
// TODO: add delete
152140
}, // function used to perform after pressing the button
153141
child: const Text(
154142
'YES',
@@ -185,10 +173,11 @@ class BookingDetails extends StatelessWidget {
185173
);
186174
}
187175

188-
void avlblcarpools() {
176+
Future<void> avlblcarpools() async {
189177
if (carpools.length != 0) {
190-
for (int i = 0; i < carpools.length; i++) {
191-
String name = carpools[i];
178+
List<BookingRecord> value = await brs;
179+
for (int i = 0; i < value.length; i++) {
180+
String name = value[i].uid;
192181
widgetlist.add(
193182
ListTile(
194183
leading: const Icon(
@@ -198,8 +187,7 @@ class BookingDetails extends StatelessWidget {
198187
),
199188
title: Text(
200189
name,
201-
style: const TextStyle(
202-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
190+
style: const TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
203191
),
204192
tileColor: Colors.black,
205193
shape: RoundedRectangleBorder(
@@ -208,14 +196,33 @@ class BookingDetails extends StatelessWidget {
208196
),
209197
);
210198
}
199+
// for (int i = 0; i < carpools.length; i++) {
200+
// String name = carpools[i];
201+
// widgetlist.add(
202+
// ListTile(
203+
// leading: const Icon(
204+
// Icons.person,
205+
// color: Colors.blue,
206+
// size: 22,
207+
// ),
208+
// title: Text(
209+
// name,
210+
// style: const TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
211+
// ),
212+
// tileColor: Colors.black,
213+
// shape: RoundedRectangleBorder(
214+
// borderRadius: BorderRadius.circular(12),
215+
// ),
216+
// ),
217+
// );
218+
// }
211219
} else {
212220
widgetlist.add(
213221
const ListTile(
214222
title: Center(
215223
child: Text(
216224
"Sorry, there are no carpools available in your time slot",
217-
style: TextStyle(
218-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
225+
style: TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
219226
),
220227
),
221228
tileColor: Colors.black,

lib/home.dart

Lines changed: 81 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,17 @@ class Homepage extends State<Home> {
2727
style: TextStyle(color: Colors.white, fontFamily: 'Helvetica'),
2828
),
2929
));
30-
List<a.Interval> userintervals = [a.Interval(2, 3), a.Interval(5, 6)];
30+
31+
// List<a.Interval> userintervals = [];
32+
33+
User curUser = LoginForm.u;
34+
late BookingRecord? curBookingRecord;
35+
late int curIntervalIndex;
36+
37+
bool didOpenDialog = false;
3138

3239
Future<void> OpenDialog() async {
40+
didOpenDialog = true;
3341
switch (await showDialog(
3442
context: context,
3543
builder: (BuildContext context) {
@@ -85,137 +93,105 @@ class Homepage extends State<Home> {
8593
})) {
8694
case Options.ShowDetails:
8795
// Let's go.
88-
Navigator.push(
89-
context,
90-
MaterialPageRoute(
91-
builder: (context) =>
92-
BookingDetails("11-02-2022", "2:00", "3:00")));
96+
Navigator.push(context, MaterialPageRoute(builder: (context) => BookingDetails("11-02-2022", "2:00", "3:00", br: curBookingRecord)));
97+
// TODO: connect with backend
9398
print("show details clicked");
9499
break;
95100
case Options.Remove:
96101
//remove stuff from databse
97102
//call build ui
103+
if (curIntervalIndex != -1) {
104+
LoginForm.u.deleteBooking(curBookingRecord!, curBookingRecord!.intervals[curIntervalIndex]);
105+
}
106+
98107
print("remove clicked");
99108
break;
100109
}
110+
curIntervalIndex = -1;
101111
}
102112

103113
@override
104114
Widget build(BuildContext context) {
105-
//bookings();
106-
return Scaffold(
107-
backgroundColor: Colors.black,
108-
body: Container(
109-
child: ListView.builder(
110-
padding: const EdgeInsets.all(10),
111-
itemCount: userintervals.length,
112-
itemBuilder: (BuildContext context, int index) {
113-
//print(LoginForm.u.present);
114-
String starttime = userintervals[index].start.toString() + ":00";
115-
String endtime = userintervals[index].end.toString() + ":00";
116-
117-
return Container(
118-
margin: const EdgeInsets.all(7),
119-
child: ListTile(
120-
leading: const Icon(
121-
Icons.car_rental,
122-
color: Colors.white,
123-
),
124-
title: Text(
125-
"Booking Time: $starttime to $endtime",
126-
style: const TextStyle(color: Colors.white),
127-
),
128-
tileColor: const Color(0xFF319177),
129-
shape: RoundedRectangleBorder(
130-
borderRadius: BorderRadius.circular(10),
131-
),
132-
trailing: IconButton(
133-
onPressed: () {
134-
OpenDialog();
135-
},
136-
icon: const Icon(
137-
Icons.more_vert,
138-
color: Colors.white,
139-
)),
140-
),
141-
);
142-
},
143-
),
144-
),
145-
);
115+
setbookings();
116+
return Scaffold(backgroundColor: Colors.black, body: presentwidget);
146117
}
147118

148119
void bookings() {
149120
setState(() {
150-
if (userintervals.length != 0) {
151-
print(0);
152-
presentwidget = Container(
153-
child: ListView.builder(
154-
padding: const EdgeInsets.all(10),
155-
itemCount: userintervals.length,
156-
itemBuilder: (BuildContext context, int index) {
157-
//print(LoginForm.u.present);
158-
String starttime = userintervals[index].start.toString() + ":00";
159-
String endtime = userintervals[index].end.toString() + ":00";
160-
161-
return Container(
162-
margin: const EdgeInsets.all(10),
163-
child: Card(
164-
shape: RoundedRectangleBorder(
165-
borderRadius: BorderRadius.circular(12),
166-
),
167-
child: ListTile(
168-
leading: const Icon(
169-
Icons.car_rental,
170-
color: Colors.white,
171-
),
172-
title: Text(
173-
"Booking Time: $starttime to $endtime",
174-
style: const TextStyle(color: Colors.white),
175-
),
176-
tileColor: Colors.teal,
121+
if (curBookingRecord != null) {
122+
if (curBookingRecord!.intervals.isNotEmpty) {
123+
print(0);
124+
presentwidget = Container(
125+
child: ListView.builder(
126+
padding: const EdgeInsets.all(10),
127+
itemCount: curBookingRecord!.intervals.length,
128+
itemBuilder: (BuildContext context, int index) {
129+
//print(LoginForm.u.present);
130+
String starttime = curBookingRecord!.intervals[index].start.toString() + ":00";
131+
String endtime = curBookingRecord!.intervals[index].end.toString() + ":00";
132+
133+
return Container(
134+
margin: const EdgeInsets.all(10),
135+
child: Card(
177136
shape: RoundedRectangleBorder(
178137
borderRadius: BorderRadius.circular(12),
179138
),
139+
child: ListTile(
140+
leading: const Icon(
141+
Icons.car_rental,
142+
color: Colors.white,
143+
),
144+
title: Text(
145+
"Booking Time: $starttime to $endtime",
146+
style: const TextStyle(color: Colors.white),
147+
),
148+
tileColor: Colors.teal,
149+
shape: RoundedRectangleBorder(
150+
borderRadius: BorderRadius.circular(12),
151+
),
152+
trailing: IconButton(
153+
onPressed: () {
154+
curIntervalIndex = index;
155+
OpenDialog().then((value) => bookings());
156+
},
157+
icon: const Icon(
158+
Icons.more_vert,
159+
color: Colors.white,
160+
))),
180161
),
181-
),
182-
);
183-
},
184-
),
185-
);
186-
} else {
187-
print(1);
188-
presentwidget = Container(
189-
child: const Center(
190-
child: Text(
191-
"You have no bookings available for the selected date.",
192-
style: TextStyle(color: Colors.white, fontFamily: 'Helvetica'),
193-
),
194-
));
162+
);
163+
},
164+
),
165+
);
166+
} else {
167+
print(1);
168+
presentwidget = Container(
169+
child: const Center(
170+
child: Text(
171+
"You have no bookings available for the selected date.",
172+
style: TextStyle(color: Colors.white, fontFamily: 'Helvetica'),
173+
),
174+
));
175+
}
195176
}
196177
});
197178
}
198179

199180
void setbookings() async {
200181
print("setbookings called");
201-
bool flag = false;
202-
List<BookingRecord> temp = LoginForm.u.bookingRecords;
203182
var newFormat = DateFormat("yyyy-MM-dd");
204-
String dt = newFormat.format(LoginForm.u.present!);
205-
for (int i = 0; i < temp.length; i++) {
206-
if (dt == temp[i].date) {
207-
print("bookings found");
208-
for (int j = 0; j < temp[i].intervals.length; j++) {
209-
userintervals.add(temp[i].intervals[j]);
210-
}
211-
flag = true;
212-
print(userintervals.length);
213-
}
214-
}
215-
if (!flag) {
216-
print("karan");
217-
userintervals.clear();
218-
}
183+
String dt = "";
184+
if (LoginForm.u.present != null) dt = newFormat.format(LoginForm.u.present!);
185+
186+
curBookingRecord = null;
187+
curIntervalIndex = -1;
188+
curUser = LoginForm.u;
189+
190+
// I have preset Date, there might be booking on that day or not
191+
// User -> BookingRecord
192+
// if (curBookingRecord is null) means that day has no record
193+
194+
curBookingRecord = curUser.bookingRecordExists(dt);
219195
bookings();
220196
}
221197
}

lib/main.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'package:carpool/landing.dart';
2+
import 'package:carpool/user.dart';
23
import 'package:firebase_core/firebase_core.dart';
34
import 'package:flutter/material.dart';
45
import 'LoginForm.dart';
@@ -40,6 +41,11 @@ class _LoginPageState extends State<LoginPage> {
4041

4142
@override
4243
Widget build(BuildContext context) {
44+
LoginForm.u = User(rollNumber: "IMT2020056", emailId: "[email protected]", dateRecords: []);
45+
LoginForm.u.addBooking(DateTime(2022, 1, 4), 3, 5);
46+
LoginForm.u.addBooking(DateTime(2022, 1, 4), 6, 9);
47+
LoginForm.u.update();
48+
4349
return Scaffold(
4450
backgroundColor: Colors.black,
4551
body: Stack(

0 commit comments

Comments
 (0)