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