· 4 years ago · Sep 11, 2021, 09:04 AM
1
2
3import 'dart:convert';
4import 'dart:ffi';
5import 'package:date_time_picker/date_time_picker.dart';
6import 'package:flutter/cupertino.dart';
7import 'package:flutter/material.dart';
8import 'package:http/http.dart' as http;
9import 'package:medbo/Booking/PathologicalMultipleBooking/testModel.dart';
10import 'AllPathLabTestModel.dart';
11import 'GetTestFeeModel.dart';
12
13
14class GetTestFeeMap {
15String? encPartnerId;
16String? encTestId;
17String? fee;
18String? discountedFee;
19String? bookingFee;
20
21GetTestFeeMap(
22 {this.encPartnerId,
23 this.encTestId,
24 this.fee,
25 this.discountedFee,
26 this.bookingFee});
27
28GetTestFeeMap.fromJson(Map<String, dynamic> json) {
29 encPartnerId = json['EncPartnerId'];
30 encTestId = json['EncTestId'];
31 fee = json['Fee'];
32 discountedFee = json['DiscountedFee'];
33 bookingFee = json['BookingFee'];
34}
35
36Map<String, dynamic> toJson() {
37 final Map<String, dynamic> data = new Map<String, dynamic>();
38 data['EncPartnerId'] = this.encPartnerId;
39 data['EncTestId'] = this.encTestId;
40 data['Fee'] = this.fee;
41 data['DiscountedFee'] = this.discountedFee;
42 data['BookingFee'] = this.bookingFee;
43 return data;
44 }
45}
46
47
48
49class MultipleTestBooking extends StatefulWidget {
50 //const MultipleTestBooking({required Key key}) : super(key: key);
51
52 @override
53 _MultipleTestBookingState createState() => _MultipleTestBookingState();
54}
55
56class _MultipleTestBookingState extends State<MultipleTestBooking> {
57
58
59 List<GetTestFeeMap> reponseArray =[]; // Storing API response || later showing test fee in table format
60 int feeSum = 0 ;
61 int discountSum = 0;
62 int bookingSum = 0;
63
64 GetTestFeeMap? getTestFeeObj;
65
66 Partner? _selectedLab;
67 Datum? _selectedTest;
68 Future? getAllPathLabResults;
69 Future? getTestByLabResult;
70
71 String encLabId = '';
72 String encTestId = '';
73 String testName ='';
74
75 void initState() {
76 super.initState();
77 getAllPathLabResults = allPathLab();
78 getTestByLabResult = getTestByLab();
79 }
80
81 String _selectedDate = DateTime.now().toString();
82//============================================================================All Lab list API==========================
83 Future<List<Partner>> allPathLab() async {
84 var jsonResponse;
85 var response = await http.post(Uri.parse("http://medbo.digitalicon.in/api/medboapi/AllPathLab"),
86 body: ({ }));
87 if (response.statusCode == 200) {
88 print("Correct");
89 jsonResponse = json.decode(response.body.toString());
90 print(jsonResponse);
91
92 AllPathLabTestModel dataModel = allPathLabTestModelFromJson(response.body);
93 print(dataModel.partner.length);
94 for (final item in dataModel.partner) {
95 print("This are the hte LAB name :${item.partnerName}");
96 }
97
98 List<Partner> arrData = dataModel.partner; // this "partner" is actual json array of data[]
99 return arrData;
100 } else {
101 print("Wrong URL");
102 throw Exception("Faild to fetch");
103 }
104 }
105//============================================================== Dependent Test dropdown list Api ============================
106
107 Future<List<Datum>> getTestByLab() async {
108 print("This is the LabId :$encLabId");
109 print("This is the EncTestId :$encTestId");
110 _selectedTest = null as Datum;
111 var response = await http.post(Uri.parse("http://medbo.digitalicon.in/api/medboapi/GetTestByLab"),
112 body: ({
113 "EncId": encLabId
114 }));
115
116 if (response.statusCode == 200) {
117 final dataModel = dataModelFromJson(response.body);
118 print(dataModel.data.length);
119 for (final item in dataModel.data) {
120 print("This are hte test names :${item.testName}");
121 }
122
123
124 List<Datum> arrData = dataModel.data;
125 return arrData;
126 }
127
128 return [];
129 }
130//=====================================================================Get Test Fee Api===========================================
131 Future<void> GetTestFee() async {
132 var jsonResponse;
133 if (encTestId.isNotEmpty) {
134 var response = await http.post(
135 Uri.parse("http://medbo.digitalicon.in/api/medboapi/GetTestFee"),
136 body: ({
137 'EncPartnerId': encLabId,
138 'EncTestId': encTestId,
139
140 }));
141 if (response.statusCode == 200) {
142 print("Correct");
143 print(response.body);
144 jsonResponse = json.decode(response.body.toString());
145 print(jsonResponse);
146 getTestFeeObj=GetTestFeeMap.fromJson(jsonResponse);
147 setState(() {
148 reponseArray.add(getTestFeeObj!); // Adding data to my Arraylist
149 for(GetTestFeeMap elem in reponseArray){
150 feeSum += elem.fee as int;
151 discountSum += elem.discountedFee as int; // Doing calculation here
152 bookingSum += elem.bookingFee as int;
153 }
154 print(feeSum);
155 print(discountSum);
156 print(discountSum);
157 });
158
159 } else {
160 throw Exception("Faild to fetch");
161 }
162 } else {
163 throw Exception("Faild to fetch");
164 }
165 //throw Exception("Faild to fetch");
166 //return GetTestFee();
167 }
168
169//===========================================================================================================================
170 @override
171 Widget build(BuildContext context) {
172 var screenWidth = MediaQuery.of(context).size.width;
173 var screenHeight = MediaQuery.of(context).size.height;
174 var blockSizeHorizontal = (screenWidth / 100);
175 var blockSizeVertical = (screenHeight / 100);
176
177 return Scaffold(
178 body: SafeArea(
179 child: SingleChildScrollView(
180 child: Container(
181 child: Column(
182 children: [
183 Padding(
184 padding: const EdgeInsets.all(8.0),
185 child: ListTile(
186 title: Text("Booking Information",
187 style: TextStyle(
188 fontWeight: FontWeight.bold,
189 fontSize: blockSizeHorizontal * 5,
190 fontFamily: 'Poppins',
191 color: Theme.of(context).primaryColor,
192 )),
193 subtitle: Text("Preferred Visit Date"),
194 ),
195 ),
196 Container(
197 margin: EdgeInsets.only(left: 20),
198 padding: EdgeInsets.only(left: 0, right: 150),
199 decoration: BoxDecoration(
200 color: Colors.lightBlue[50],
201 borderRadius: BorderRadius.all(Radius.circular(12)),
202 ),
203 child: Padding(
204 padding: const EdgeInsets.all(8.0),
205 child: DateTimePicker(
206 initialValue: DateTime.now().toString(),
207 //initialValue:'', // initialValue or controller.text can be null, empty or a DateTime string otherwise it will throw an error.
208 type: DateTimePickerType.date,
209 dateLabelText: 'Select Date',
210 style: TextStyle(
211 fontWeight: FontWeight.bold,
212 fontSize: blockSizeHorizontal * 3.5,
213 fontFamily: 'Poppins',
214 color: Colors.green,
215 letterSpacing: 2.0,
216 ),
217 firstDate: DateTime.now(),
218 lastDate: DateTime.now().add(Duration(days: 30)),
219 // This will add one year from current date
220 validator: (value) {
221 return null;
222 },
223 onChanged: (value) {
224 if (value.isNotEmpty) {
225 setState(() {
226 _selectedDate = value;
227 });
228 }
229 },
230 onSaved: (value) {
231 if (value.isNotEmpty) {
232 _selectedDate = value;
233 }
234 },
235 ),
236 ),
237 ),
238
239 //=========================================================== INITIAL drop down=====================
240
241 ListTile(
242 title: Text(
243 "Select Pathological Lab",
244 style: TextStyle(
245 fontWeight: FontWeight.bold,
246 fontSize: blockSizeHorizontal * 4.0,
247 fontFamily: 'Poppins',
248 color: Theme.of(context).primaryColor,
249 ),
250 ),
251 ),
252
253 Container(
254 child: FutureBuilder<List<Partner>>(
255 future: getAllPathLabResults as Future<List<Partner>>,
256 builder: (BuildContext context, AsyncSnapshot snapshot) {
257 if (snapshot.connectionState != ConnectionState.done) {
258 return CircularProgressIndicator();
259 }
260 if (snapshot.hasError) {
261 return Text("Somthing went wrong");
262 }
263
264 if (snapshot.hasData) {
265 List<Partner> data =
266 snapshot.hasData ? snapshot.data : [];
267 return Padding(
268 padding: const EdgeInsets.only(left:20.0, right: 150),
269 child: DropdownButton<Partner>(
270 value: _selectedLab,
271 hint: Text("Select Lab"),
272 //underline: SizedBox(),
273 isExpanded: true,
274 items: data
275 .map((Partner data) => DropdownMenuItem<Partner>(
276 child: Text("${data.partnerName}"),
277 value: data,
278 ))
279 .toList()
280 .cast<DropdownMenuItem<Partner>>(),
281 onChanged: (value) {
282 setState(() {
283 _selectedLab = value!;
284
285 encLabId = value.encPartnerId;
286 getTestByLabResult = getTestByLab();
287 });
288 //GetTestByLab(value!.encPartnerId); // passing encid to my next API function
289 // GetTestByLab();
290 },
291 ),
292 );
293 }
294 return Text("Waiting for Internet Connection");
295 },
296 ),
297 ),
298
299 //=========================================================== Dependent drop down============================
300
301 ListTile(
302 title: Text(
303 "Test Name",
304 style: TextStyle(
305 fontWeight: FontWeight.bold,
306 fontSize: blockSizeHorizontal * 4.0,
307 fontFamily: 'Poppins',
308 color: Theme.of(context).primaryColor,
309 ),
310 ),
311 ),
312
313 Container(
314 child: FutureBuilder<List<Datum>>(
315 future: getTestByLabResult as Future<List<Datum>>,
316 builder: (BuildContext context, AsyncSnapshot snapshot) {
317 if (snapshot.connectionState != ConnectionState.done) {
318 return CircularProgressIndicator();
319 }
320 if (snapshot.hasError) {
321 return Text("Something wrong");
322 }
323
324 if (snapshot.hasData) {
325 List<Datum> data = snapshot.hasData ? snapshot.data : [];
326
327 return Padding(
328 padding: const EdgeInsets.only(left:20.0, right: 150),
329 child: DropdownButton<Datum>(
330 value: _selectedTest,
331 hint: Text(""),
332 //underline: SizedBox(),
333 isExpanded: true,
334 items: data
335 .map((Datum data) => DropdownMenuItem<Datum>(
336 child: Text("${data.testName}"),
337 value: data,
338 ))
339 .toList()
340 .cast<DropdownMenuItem<Datum>>(),
341 onChanged: (value) {
342 print("This is the TestName : ${value!.testName}");
343 print("This is the EncTestId : ${value.testId}");
344 setState(() {
345 encTestId = value.testId;
346 testName = value.testName;
347 _selectedTest = value;
348 });
349 //GetTestByLab(value!.encPartnerId); // passing encid to my next API function
350 }),
351 );
352 }
353 return Text("Waiting for Internet Connection");
354 },
355 ),
356 ),
357
358 OutlinedButton(
359 onPressed: (){
360 setState(() {
361 //GetTestFee();
362 });
363 GetTestFee();
364 },
365 child:Text("Add")),
366
367
368
369
370
371 DataTable(
372 columnSpacing: 13.0,
373 columns: <DataColumn>[
374 //DataColumn(label: Text("encPartnerId")),
375 //DataColumn(label: Text("encTestId")),
376 // DataColumn(label: Text("TestName")),
377 DataColumn(label: Text("Fee")),
378 DataColumn(label: Text("Discounted Fee")),
379 DataColumn(label: Text("Booking Fee")),
380 ],
381
382 rows:reponseArray.map((testRowData){
383 return DataRow(
384 cells: [
385 //DataCell(Text(testName)),
386 DataCell(Text(testRowData.fee ?? '')),
387 DataCell(Text(testRowData.discountedFee ?? '')),
388 DataCell(Text(testRowData.bookingFee ?? ''))
389 ]
390 );
391 }).toList()
392 ),
393
394
395
396 // Container(
397 // child:
398 // Row(
399 // children: [
400 // Text(feeSum as String),
401 // Text(discountSum as String),
402 // Text(bookingSum as String),
403 // ],
404 // ),
405 // )
406
407
408 ],
409 ),
410 ),
411 ),
412 ),
413 );
414 }
415
416
417
418}