@@ -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}
0 commit comments