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