Skip to content

Commit d6fa871

Browse files
raddi1972MnCSSJ4xishaanj0412
committed
changes
Co-authored-by: Monjoy Narayan Choudhury <[email protected]> Co-authored-by: ishaanj0412 <[email protected]>
1 parent e80963e commit d6fa871

File tree

4 files changed

+80
-139
lines changed

4 files changed

+80
-139
lines changed

lib/bookingdetails.dart

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ import 'package:flutter/material.dart';
33
class BookingDetails extends StatelessWidget {
44
late List<Widget> widgetlist;
55

6-
BookingDetails(this.date, this.starttime, this.endtime, {Key? key})
7-
: super(key: key) {
6+
BookingDetails(this.date, this.starttime, this.endtime, {Key? key}) : super(key: key) {
87
widgetlist = [
98
const ListTile(
109
title: Center(
1110
child: Text(
1211
"Details",
13-
style: TextStyle(
14-
color: Colors.blue,
15-
fontFamily: 'Helvetica',
16-
fontSize: 22,
17-
fontWeight: FontWeight.bold),
12+
style: TextStyle(color: Colors.blue, fontFamily: 'Helvetica', fontSize: 22, fontWeight: FontWeight.bold),
1813
),
1914
),
2015
tileColor: Colors.black,
@@ -27,8 +22,7 @@ class BookingDetails extends StatelessWidget {
2722
),
2823
title: Text(
2924
"Date: $date",
30-
style: const TextStyle(
31-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
25+
style: const TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
3226
),
3327
tileColor: Colors.black,
3428
),
@@ -40,20 +34,15 @@ class BookingDetails extends StatelessWidget {
4034
),
4135
title: Text(
4236
"Time Slot: $starttime Hours to $endtime Hours",
43-
style: const TextStyle(
44-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
37+
style: const TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
4538
),
4639
tileColor: Colors.black,
4740
),
4841
const ListTile(
4942
title: Center(
5043
child: Text(
5144
"Available Carpools",
52-
style: TextStyle(
53-
color: Colors.blue,
54-
fontFamily: 'Helvetica',
55-
fontSize: 22,
56-
fontWeight: FontWeight.bold),
45+
style: TextStyle(color: Colors.blue, fontFamily: 'Helvetica', fontSize: 22, fontWeight: FontWeight.bold),
5746
),
5847
),
5948
tileColor: Colors.black,
@@ -64,16 +53,8 @@ class BookingDetails extends StatelessWidget {
6453
final String date;
6554
final String starttime;
6655
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-
];
56+
List<String> carpools = ["Ishaan Jalan", "Rudransh Dixit", "hewwo", "manda", "ramesh", "mukesh", "sukesh", "nilesh"];
57+
// TODO: add getBookingData..
7758

7859
@override
7960
Widget build(BuildContext context) {
@@ -198,8 +179,7 @@ class BookingDetails extends StatelessWidget {
198179
),
199180
title: Text(
200181
name,
201-
style: const TextStyle(
202-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
182+
style: const TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
203183
),
204184
tileColor: Colors.black,
205185
shape: RoundedRectangleBorder(
@@ -214,8 +194,7 @@ class BookingDetails extends StatelessWidget {
214194
title: Center(
215195
child: Text(
216196
"Sorry, there are no carpools available in your time slot",
217-
style: TextStyle(
218-
color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
197+
style: TextStyle(color: Colors.white, fontFamily: 'Helvetica', fontSize: 15),
219198
),
220199
),
221200
tileColor: Colors.black,

lib/home.dart

Lines changed: 63 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ class Home extends StatefulWidget {
2020
enum Options { Remove, ShowDetails }
2121

2222
class Homepage extends State<Home> {
23-
Widget presentwidget = Container(
24-
child: const Center(
25-
child: Text(
26-
"You have no bookings available for the selected date.",
27-
style: TextStyle(color: Colors.white, fontFamily: 'Helvetica'),
28-
),
29-
));
30-
List<a.Interval> userintervals = [a.Interval(2, 3), a.Interval(5, 6)];
23+
late Widget presentwidget;
24+
25+
// List<a.Interval> userintervals = [];
26+
27+
User curUser = LoginForm.u;
28+
late BookingRecord? curBookingRecord;
29+
late int curIntervalIndex;
3130

3231
Future<void> OpenDialog() async {
3332
switch (await showDialog(
@@ -85,16 +84,14 @@ class Homepage extends State<Home> {
8584
})) {
8685
case Options.ShowDetails:
8786
// Let's go.
88-
Navigator.push(
89-
context,
90-
MaterialPageRoute(
91-
builder: (context) =>
92-
BookingDetails("11-02-2022", "2:00", "3:00")));
87+
Navigator.push(context, MaterialPageRoute(builder: (context) => BookingDetails("11-02-2022", "2:00", "3:00")));
88+
// TODO: connect with backend
9389
print("show details clicked");
9490
break;
9591
case Options.Remove:
9692
//remove stuff from databse
9793
//call build ui
94+
9895
print("remove clicked");
9996
break;
10097
}
@@ -103,119 +100,76 @@ class Homepage extends State<Home> {
103100
@override
104101
Widget build(BuildContext context) {
105102
//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-
);
103+
return Scaffold(backgroundColor: Colors.black, body: presentwidget);
146104
}
147105

148106
void bookings() {
149107
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";
108+
if (curBookingRecord != null) {
109+
if (curBookingRecord!.intervals.isNotEmpty) {
110+
print(0);
111+
presentwidget = Container(
112+
child: ListView.builder(
113+
padding: const EdgeInsets.all(10),
114+
itemCount: curBookingRecord!.intervals.length,
115+
itemBuilder: (BuildContext context, int index) {
116+
//print(LoginForm.u.present);
117+
String starttime = curBookingRecord!.intervals[index].start.toString() + ":00";
118+
String endtime = curBookingRecord!.intervals[index].end.toString() + ":00";
160119

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,
120+
return Container(
121+
margin: const EdgeInsets.all(10),
122+
child: Card(
177123
shape: RoundedRectangleBorder(
178124
borderRadius: BorderRadius.circular(12),
179125
),
126+
child: ListTile(
127+
leading: const Icon(
128+
Icons.car_rental,
129+
color: Colors.white,
130+
),
131+
title: Text(
132+
"Booking Time: $starttime to $endtime",
133+
style: const TextStyle(color: Colors.white),
134+
),
135+
tileColor: Colors.teal,
136+
shape: RoundedRectangleBorder(
137+
borderRadius: BorderRadius.circular(12),
138+
),
139+
trailing: IconButton(
140+
onPressed: () {
141+
OpenDialog();
142+
},
143+
icon: const Icon(
144+
Icons.more_vert,
145+
color: Colors.white,
146+
))),
180147
),
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-
));
148+
);
149+
},
150+
),
151+
);
152+
} else {
153+
print(1);
154+
presentwidget = Container(
155+
child: const Center(
156+
child: Text(
157+
"You have no bookings available for the selected date.",
158+
style: TextStyle(color: Colors.white, fontFamily: 'Helvetica'),
159+
),
160+
));
161+
}
195162
}
196163
});
197164
}
198165

199166
void setbookings() async {
200167
print("setbookings called");
201-
bool flag = false;
202-
List<BookingRecord> temp = LoginForm.u.bookingRecords;
203168
var newFormat = DateFormat("yyyy-MM-dd");
204169
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-
}
170+
curBookingRecord = null;
171+
curIntervalIndex = -1;
172+
curUser = LoginForm.u;
219173
bookings();
220174
}
221175
}

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(

lib/user.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ class User {
7373
required List<DateTime> this.dateRecords,
7474
}) {
7575
bookingRecords = [];
76+
present = DateTime.now();
77+
selected = DateTime.now();
7678
// TODO: fetch from database the dateRecords which will be stored for a old user
7779

7880
// TODO: then fetch all the bookingRecord for the person (Only upcoming ones)

0 commit comments

Comments
 (0)