· 6 years ago · Mar 09, 2020, 01:00 PM
1import 'dart:ui';
2
3import 'package:flutter/material.dart';
4import 'package:flutter_bloc/flutter_bloc.dart';
5import 'package:ipartneragent/Model/HealthProductEntity.dart';
6import 'package:ipartneragent/api_reponses/retail_login_response.dart';
7import 'package:ipartneragent/blocs/healthplans/healthplan_bloc.dart';
8import 'package:ipartneragent/api_reponses/stateresponse.dart';
9import 'package:ipartneragent/components/BackgroundImage.dart';
10import 'package:ipartneragent/layouts/HealthQuotations/health_quotation_common.dart';
11import 'package:ipartneragent/layouts/HealthQuotations/ppap_quotation.dart';
12import 'HealthQuotations/health_protect_quotation.dart';
13import 'package:ipartneragent/layouts/Healtth_Wordings/health_protect_wording.dart';
14import 'package:ipartneragent/layouts/drawerlayout.dart';
15
16import 'package:ipartneragent/utilities/Custom_TextStyles.dart';
17import 'package:ipartneragent/utilities/size_config.dart';
18import 'package:ipartneragent/widgets/CustomAppBar.dart';
19import 'package:ipartneragent/widgets/transparent_loader.dart';
20
21class HealthPolicyLayout extends StatefulWidget {
22 final RetailLoginResponse retailLoginResponse;
23 // final List<StateResponse> stateresponse;
24 const HealthPolicyLayout({
25 Key key,
26 this.retailLoginResponse,
27 }) : super(key: key);
28 @override
29 _HealthPolicyLayoutState createState() => _HealthPolicyLayoutState(
30 retailLoginRsponse: this.retailLoginResponse,
31 );
32}
33
34final GlobalKey<ScaffoldState> _healthPolicyScaffoldKey =
35 new GlobalKey<ScaffoldState>();
36
37class _HealthPolicyLayoutState extends State<HealthPolicyLayout> {
38 RetailLoginResponse retailLoginRsponse;
39 // List<StateResponse> stateresponse;
40 _HealthPolicyLayoutState({
41 this.retailLoginRsponse,
42 });
43
44 static List<HealthProductEntity> _productNames = [];
45 int _currVal = 1;
46 String _currText;
47
48//Initial static Product List
49
50 List<HealthProductEntity> _healthProductsAvailable = [
51 HealthProductEntity(
52 title: 'Health Protect',
53 id: 14,
54 healthplanEvent: HealthProtectEvent(
55 // userId: retailLoginRsponse.agentId.toString(),
56 userId: "5924600",
57 password: 'Lombard@123',
58 subType: 14.toString(),
59 userName: 'IM-46236'),
60 ),
61 HealthProductEntity(
62 title: 'Health Protect Plus',
63 id: 12,
64 healthplanEvent: HealthProtectPlusEvent(
65 // userId: retailLoginRsponse.agentId.toString(),
66 userId: "5924600",
67 password: 'Lombard@123',
68 subType: 14.toString(),
69 userName: 'IM-46236'),
70 ),
71 HealthProductEntity(
72 title: 'Health Smart',
73 id: 16,
74 healthplanEvent: HealthSmartEvent(
75 userId: "5924600",
76 password: 'Lombard@123',
77 subType: 14.toString(),
78 userName: 'IM-46236',
79 )),
80 HealthProductEntity(
81 title: 'Health Smart Plus',
82 id: 15,
83 healthplanEvent: HealthSmartPlusEvent(
84 userId: "5924600",
85 password: 'Lombard@123',
86 subType: 14.toString(),
87 userName: 'IM-46236',
88 )),
89 HealthProductEntity(
90 title: 'iHealth', id: 17, healthplanEvent: IHealthEvent()),
91 HealthProductEntity(
92 title: 'Health Booster',
93 id: 19,
94 healthplanEvent: HealthBoosterEvent(
95 userId: "5924600",
96 password: 'Lombard@123',
97 subType: 19.toString(),
98 userName: 'IM-46236',
99 )),
100 HealthProductEntity(title: 'PPAP', id: 21, healthplanEvent: PPAPEvent()),
101 HealthProductEntity(
102 title: 'Hospifund', id: 25, healthplanEvent: HospifundEvent()),
103 ];
104
105 HealthplanBloc healthplanBloc;
106
107//TODO:Implement the function;
108//Function to generate the _products_Available list from the loginResponse api
109 List healthProductGenerator(RetailLoginResponse response) {
110 int index = 0;
111 Map<String, bool> healthProducts =
112 response.mappedProduct.health.healthChiSubProducts;
113 Health healthResponse = response.mappedProduct.health;
114 print('The length is : ${_healthProductsAvailable.length}');
115//Filter out thr HealthPorductList from the api reponse
116 /////////Danger is here ------remove the do-undo the ! sign in response,mappedProduct.health.isHealthCHIMapped
117 if (!response.mappedProduct.health.isHealthChiMapped) {
118 _healthProductsAvailable.removeRange(0, 5);
119 }
120
121 if (response.mappedProduct.health.isHealthChiMapped) {
122 Map<String, bool> healthProducts =
123 response.mappedProduct.health.healthChiSubProducts;
124 if (!healthProducts['Visible_HealthProtect'])
125 _healthProductsAvailable.removeAt(0);
126 if (!healthProducts['Visible_HelathProtectPlus'])
127 _healthProductsAvailable.removeAt(0);
128 if (!healthProducts['Visible_HealthSecure'])
129 _healthProductsAvailable.removeAt(0);
130 if (!healthProducts['Visible_HealthSecurePlus'])
131 _healthProductsAvailable.removeAt(0);
132 if (!healthProducts['Visible_iHealth'])
133 _healthProductsAvailable.removeAt(0);
134 }
135 if (!healthResponse.isHospifundMapped)
136 _healthProductsAvailable.removeLast();
137 if (!healthResponse.isHealthPpapMapped)
138 _healthProductsAvailable.removeWhere((item) => item.id == 21);
139 if (!healthResponse.isHealthBoosterMapped)
140 _healthProductsAvailable.removeWhere((item) => item.id == 19);
141
142 print(_healthProductsAvailable);
143
144 return _healthProductsAvailable;
145 }
146
147 @override
148 void initState() {
149 // TODO: implement initState
150 super.initState();
151 print(this.retailLoginRsponse);
152 _productNames = healthProductGenerator(this.retailLoginRsponse);
153 print('_productNames $_productNames');
154 _currText = _productNames[0].title;
155 print('_currtext $_currText');
156 triggerInitialHealthPolicyState(_currText, retailLoginRsponse);
157 healthplanBloc = HealthplanBloc();
158 }
159
160 @override
161 Widget build(BuildContext context) {
162 return BlocBuilder<HealthplanBloc, HealthplanState>(
163 bloc: healthplanBloc,
164 builder: (context, state) {
165 return Scaffold(
166 key: _healthPolicyScaffoldKey,
167 drawer: Theme(
168 data: Theme.of(context).copyWith(
169 canvasColor: Colors.transparent,
170 ),
171 child: AppDrawer(),
172 ),
173 appBar: CustomAppBar(
174 appDrawerFunction: () =>
175 _healthPolicyScaffoldKey.currentState.openDrawer(),
176 customDrawerIcon: false,
177 title: Text(
178 'Quick Quote',
179 style: CustomTextStyles.appBarTextStyle,
180 ),
181 actions: <Widget>[],
182 ),
183 body: BlocBuilder<HealthplanBloc, HealthplanState>(
184 builder: (context, state) {
185 return SafeArea(
186 child: Stack(
187 children: <Widget>[
188 backgroundImage(),
189 SingleChildScrollView(
190 scrollDirection: Axis.vertical,
191 child: Padding(
192 padding: EdgeInsets.only(left: 10, right: 10, top: 5),
193 child: Container(
194 width: SizeConfig.blockSizeHorizontal * 98,
195 decoration: BoxDecoration(
196 shape: BoxShape.rectangle,
197
198 // border: Border(
199 // top: BorderSide(width: 5,color: Colors.white.withOpacity(0.1)),
200 // right: BorderSide(width: 5,color: Colors.redAccent.withOpacity(0.5)),
201 // bottom: BorderSide(width: 5,color: Colors.redAccent.withOpacity(0.5)),
202 // left: BorderSide(width: 5,color: Colors.white.withOpacity(0.1)
203 // )
204 // ),
205 // borderRadius: BorderRadius.all(10),
206 // borderRadius: BorderRadius.only(bottomLeft: Radius.circular()),
207 color: Colors.white.withOpacity(0.4),
208 ),
209 child: Column(
210 mainAxisSize: MainAxisSize.min,
211 crossAxisAlignment: CrossAxisAlignment.start,
212 children: <Widget>[
213 //The DropDown (with Heading) to select HealthProduct
214 productSelector(),
215 SizedBox(
216 height: 5.0,
217 ),
218//----------------The health policy parameters according to the product name wil go here
219 getMainWidget(state),
220 ],
221 ),
222 ),
223 ),
224 ),
225 ],
226 ),
227 );
228 }),
229 floatingActionButton: FloatingActionButton(
230 mini: true,
231 child: Container(
232 decoration: BoxDecoration(
233 color: Color(0xff063b6d),
234 shape: BoxShape.circle,
235 image: DecorationImage(
236 image: AssetImage(
237 'assets/images/info.png',
238 ),
239 fit: BoxFit.fill)),
240 ),
241 onPressed: () {
242 healthProtect_Wording(context);
243 },
244 ),
245 //
246 );
247 });
248 }
249
250 Widget getMainWidget(HealthplanState state) {
251 if (state is HealthplanInitialState)
252 return Center(
253 child: Container(
254 height: 200,
255 width: double.infinity,
256 child: Center(
257 child: CircularProgressIndicator(
258 backgroundColor: Colors.deepPurple,
259 ),
260 ),
261 ),
262 );
263 else if (state is HealthProtectState)
264 return HealthProtectQuotation(
265 healthPlanMasterResponse: state.response,
266 retailLoginResponse: retailLoginRsponse,
267 );
268 else if (state is HealthProtectPlusState)
269 return HealthQuotationCommon(
270 healthPlanMasterResponse: state.response,
271 retailLoginResponse: retailLoginRsponse,
272 healthQuotationOptions: HealthQuotationOptions.HealthProtectPlus,
273 );
274 else if (state is HealthSmartState)
275 return HealthQuotationCommon(
276 healthPlanMasterResponse: state.response,
277 retailLoginResponse: retailLoginRsponse,
278 healthQuotationOptions: HealthQuotationOptions.HealthSmart,
279 );
280 else if (state is HealthSmartPlusState)
281 return HealthQuotationCommon(
282 healthPlanMasterResponse: state.response,
283 retailLoginResponse: retailLoginRsponse,
284 healthQuotationOptions: HealthQuotationOptions.HealthSmartPlus,
285 );
286 else if (state is HealthBoosterState)
287 return HealthQuotationCommon(
288 healthPlanMasterResponse: state.response,
289 retailLoginResponse: retailLoginRsponse,
290 healthQuotationOptions: HealthQuotationOptions.HealthBooster,
291 );
292 else if (state is PPAPState)
293 return PpapQuotation();
294 else
295 return CircularProgressIndicator();
296 }
297
298 Widget productSelector() {
299 return Column(
300 crossAxisAlignment: CrossAxisAlignment.start,
301 children: <Widget>[
302 Padding(
303 padding: EdgeInsets.only(left: 20, top: 10),
304 child: Text(
305 'Product Name',
306 style: TextStyle(color: Color(0xffb01f21)),
307 ),
308 ),
309 Padding(
310 padding: EdgeInsets.only(left: 20, top: 10, right: 50),
311 child: GestureDetector(
312 child: Container(
313 color: Colors.transparent,
314 child: Row(
315 mainAxisAlignment: MainAxisAlignment.spaceBetween,
316 children: <Widget>[
317 Text(
318 '$_currText',
319 style:
320 TextStyle(fontWeight: FontWeight.bold, fontSize: 16.5),
321 ),
322 Icon(Icons.keyboard_arrow_down),
323 ],
324 ),
325 ),
326 onTap: () async {
327 String productName = await showDialog(
328 barrierDismissible: false,
329 context: context,
330 builder: (BuildContext context) {
331 return AlertDialog(
332 shape: RoundedRectangleBorder(
333 borderRadius: BorderRadius.all(Radius.circular(20.0))),
334 title: Center(child: Text('Select Health Product')),
335 content: StatefulBuilder(
336 builder: (context, setState) {
337 return Column(
338 mainAxisSize: MainAxisSize.min,
339 children: _productNames.map((product) {
340 return RadioListTile(
341 controlAffinity: ListTileControlAffinity.trailing,
342 selected: false,
343 title: Text('${product.title}'),
344 groupValue: _currVal,
345 value: product.id,
346 onChanged: (val) {
347 setState(() {
348 _currVal = val;
349 });
350 print('Selected this: ${product.title}');
351
352 BlocProvider.of<HealthplanBloc>(context)
353 .add(product.healthplanEvent);
354 Navigator.of(context).pop(product.title);
355 },
356 );
357 }).toList(),
358 );
359 },
360 ),
361 );
362 },
363 );
364 setState(() {
365 _currText =
366 (productName != null) ? productName : 'Health Protect';
367 print('selected value: $productName');
368 });
369 },
370 ),
371 ),
372 ],
373 );
374 }
375
376//Triggers an event change on Tapping the healthPRoduct list and optionally returns the event
377 HealthplanEvent triggerInitialHealthPolicyState(
378 String caseText, RetailLoginResponse retailLoginResponse) {
379 switch (caseText) {
380 case "Health Protect Plus":
381 {
382 print('Triggerring');
383 BlocProvider.of<HealthplanBloc>(context).add(HealthProtectPlusEvent(
384 userId: retailLoginResponse.agentId.toString(),
385 password: 'Lombard@123',
386 subType: "14",
387 userName: 'IM-46236',
388 ));
389 return HealthProtectPlusEvent(
390 userId: retailLoginResponse.agentId.toString(),
391 password: 'Lombard@123',
392 subType: "14",
393 userName: 'IM-46236',
394 );
395 }
396 break;
397 case "Health Secure":
398 {
399 BlocProvider.of<HealthplanBloc>(context).add(HealthSecureEvent());
400 return HealthSecureEvent();
401 }
402 break;
403 case "Health Secure Plus":
404 {
405 BlocProvider.of<HealthplanBloc>(context).add(HealthSecurePlusEvent());
406 return HealthSecurePlusEvent();
407 }
408 break;
409 case "Health Protect":
410 {
411 BlocProvider.of<HealthplanBloc>(context).add(HealthProtectEvent(
412 userId: retailLoginResponse.agentId.toString(),
413 password: 'Lombard@123',
414 subType: "14",
415 userName: 'IM-46236'));
416 return HealthProtectEvent(
417 userId: "5924600",
418 password: 'Lombard@123',
419 subType: "14",
420 userName: 'IM-46236');
421 }
422 break;
423 case "Health Smart":
424 {
425 BlocProvider.of<HealthplanBloc>(context).add(HealthSmartEvent(
426 userId: retailLoginResponse.agentId.toString(),
427 password: 'Lombard@123',
428 subType: "14",
429 userName: 'IM-46236',
430 ));
431 return HealthSmartEvent(
432 userId: retailLoginResponse.agentId.toString(),
433 password: 'Lombard@123',
434 subType: "14",
435 userName: 'IM-46236',
436 );
437 }
438 break;
439 case "Health Smart Plus":
440 {
441 BlocProvider.of<HealthplanBloc>(context).add(HealthSmartPlusEvent(
442 userId: retailLoginResponse.agentId.toString(),
443 password: 'Lombard@123',
444 subType: "14",
445 userName: 'IM-46236',
446 ));
447 return HealthSmartPlusEvent(
448 userId: retailLoginResponse.agentId.toString(),
449 password: 'Lombard@123',
450 subType: "14",
451 userName: 'IM-46236',
452 );
453 }
454 break;
455 case "i Health":
456 {
457 BlocProvider.of<HealthplanBloc>(context).add(IHealthEvent());
458 return IHealthEvent();
459 }
460 break;
461 case "Health Booster":
462 {
463 BlocProvider.of<HealthplanBloc>(context).add(HealthBoosterEvent(
464 userId: retailLoginResponse.agentId.toString(),
465 password: 'Lombard@123',
466 subType: "19",
467 userName: 'IM-46236',
468 ));
469 return HealthBoosterEvent(
470 userId: retailLoginResponse.agentId.toString(),
471 password: 'Lombard@123',
472 subType: "19",
473 userName: 'IM-46236',
474 );
475 }
476 break;
477 case "PPAP":
478 {
479 BlocProvider.of<HealthplanBloc>(context).add(PPAPEvent());
480 return PPAPEvent();
481 }
482 break;
483 case "Hospifund":
484 {
485 BlocProvider.of<HealthplanBloc>(context).add(HospifundEvent());
486 return HospifundEvent();
487 }
488 break;
489 }
490 }
491}