@@ -20,14 +20,13 @@ class Home extends StatefulWidget {
2020enum Options { Remove , ShowDetails }
2121
2222class 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}
0 commit comments