Skip to content

Commit 7c2a3cb

Browse files
committed
connected UI to backend
1 parent d6fa871 commit 7c2a3cb

File tree

3 files changed

+72
-9
lines changed

3 files changed

+72
-9
lines changed

lib/bookingdetails.dart

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
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}) : super(key: key) {
9+
BookingDetails(this.date, this.starttime, this.endtime, {Key? key, BookingRecord? br}) : super(key: key) {
10+
brs = LoginForm.u.getBookingMatching(br!);
711
widgetlist = [
812
const ListTile(
913
title: Center(
@@ -53,6 +57,8 @@ class BookingDetails extends StatelessWidget {
5357
final String date;
5458
final String starttime;
5559
final String endtime;
60+
late Future<List<BookingRecord>> brs;
61+
// late List<BookingRecord> brs;
5662
List<String> carpools = ["Ishaan Jalan", "Rudransh Dixit", "hewwo", "manda", "ramesh", "mukesh", "sukesh", "nilesh"];
5763
// TODO: add getBookingData..
5864

@@ -130,6 +136,7 @@ class BookingDetails extends StatelessWidget {
130136
//DB deletion strategy same as home.dart
131137
Navigator.pop(context);
132138
Navigator.pop(context);
139+
// TODO: add delete
133140
}, // function used to perform after pressing the button
134141
child: const Text(
135142
'YES',
@@ -166,10 +173,11 @@ class BookingDetails extends StatelessWidget {
166173
);
167174
}
168175

169-
void avlblcarpools() {
176+
Future<void> avlblcarpools() async {
170177
if (carpools.length != 0) {
171-
for (int i = 0; i < carpools.length; i++) {
172-
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;
173181
widgetlist.add(
174182
ListTile(
175183
leading: const Icon(
@@ -188,6 +196,26 @@ class BookingDetails extends StatelessWidget {
188196
),
189197
);
190198
}
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+
// }
191219
} else {
192220
widgetlist.add(
193221
const ListTile(

lib/home.dart

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,24 @@ class Home extends StatefulWidget {
2020
enum Options { Remove, ShowDetails }
2121

2222
class Homepage extends State<Home> {
23-
late Widget presentwidget;
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+
));
2430

2531
// List<a.Interval> userintervals = [];
2632

2733
User curUser = LoginForm.u;
2834
late BookingRecord? curBookingRecord;
2935
late int curIntervalIndex;
3036

37+
bool didOpenDialog = false;
38+
3139
Future<void> OpenDialog() async {
40+
didOpenDialog = true;
3241
switch (await showDialog(
3342
context: context,
3443
builder: (BuildContext context) {
@@ -84,22 +93,26 @@ class Homepage extends State<Home> {
8493
})) {
8594
case Options.ShowDetails:
8695
// Let's go.
87-
Navigator.push(context, MaterialPageRoute(builder: (context) => 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)));
8897
// TODO: connect with backend
8998
print("show details clicked");
9099
break;
91100
case Options.Remove:
92101
//remove stuff from databse
93102
//call build ui
103+
if (curIntervalIndex != -1) {
104+
LoginForm.u.deleteBooking(curBookingRecord!, curBookingRecord!.intervals[curIntervalIndex]);
105+
}
94106

95107
print("remove clicked");
96108
break;
97109
}
110+
curIntervalIndex = -1;
98111
}
99112

100113
@override
101114
Widget build(BuildContext context) {
102-
//bookings();
115+
setbookings();
103116
return Scaffold(backgroundColor: Colors.black, body: presentwidget);
104117
}
105118

@@ -138,7 +151,8 @@ class Homepage extends State<Home> {
138151
),
139152
trailing: IconButton(
140153
onPressed: () {
141-
OpenDialog();
154+
curIntervalIndex = index;
155+
OpenDialog().then((value) => bookings());
142156
},
143157
icon: const Icon(
144158
Icons.more_vert,
@@ -166,10 +180,18 @@ class Homepage extends State<Home> {
166180
void setbookings() async {
167181
print("setbookings called");
168182
var newFormat = DateFormat("yyyy-MM-dd");
169-
String dt = newFormat.format(LoginForm.u.present!);
183+
String dt = "";
184+
if (LoginForm.u.present != null) dt = newFormat.format(LoginForm.u.present!);
185+
170186
curBookingRecord = null;
171187
curIntervalIndex = -1;
172188
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);
173195
bookings();
174196
}
175197
}

lib/user.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,19 @@ class User {
8080
// TODO: then fetch all the bookingRecord for the person (Only upcoming ones)
8181
}
8282

83+
BookingRecord? bookingRecordExists(String dt) {
84+
if (dateRecords.contains(DateTime.parse(dt))) {
85+
if (bookingRecords.contains(BookingRecord(emailId, dt))) {
86+
for (var element in bookingRecords) {
87+
if (element.uid == emailId && element.date == dt) {
88+
return element;
89+
}
90+
}
91+
}
92+
}
93+
return null;
94+
}
95+
8396
void addBooking(DateTime date, int startHour, int endHour) {
8497
// TODO: make a new booking record, add it to the bookingRecords.
8598
var newFormat = DateFormat("yyyy-MM-dd");

0 commit comments

Comments
 (0)