· 6 years ago · Mar 17, 2020, 06:50 AM
1import 'dart:ui';
2
3import 'package:flutter/material.dart';
4import 'package:flutter_bloc/flutter_bloc.dart';
5import 'package:flutter_secure_storage/flutter_secure_storage.dart';
6import 'package:ipartneragent/Model/HealthProductEntity.dart';
7import 'package:ipartneragent/api_reponses/retail_login_response.dart';
8import 'package:ipartneragent/blocs/healthplans/healthplan_bloc.dart';
9import 'package:ipartneragent/api_reponses/stateresponse.dart';
10import 'package:ipartneragent/components/BackgroundImage.dart';
11import 'package:ipartneragent/layouts/custom_platform/platform_alert_dialog.dart';
12import 'package:ipartneragent/services/all_urls.dart';
13import 'package:ipartneragent/utilities/custom_radio_text_group.dart';
14import 'package:ipartneragent/widgets/constants.dart';
15import 'HealthQuotations/health_protect_quotation.dart';
16import 'HealthQuotations/health_quotation_common.dart';
17import 'HealthQuotations/ppap_quotaion.dart';
18import 'package:ipartneragent/layouts/Healtth_Wordings/health_protect_wording.dart';
19import 'package:ipartneragent/layouts/drawerlayout.dart';
20import 'package:ipartneragent/widgets/transparent_loader.dart';
21import 'package:ipartneragent/utilities/Custom_TextStyles.dart';
22import 'package:ipartneragent/utilities/size_config.dart';
23import 'package:ipartneragent/widgets/CustomAppBar.dart';
24import 'package:ipartneragent/utilities/enums.dart';
25
26class HealthPolicyLayout extends StatefulWidget {
27 final RetailLoginResponse retailLoginResponse;
28 final String username;
29 final String password;
30 // final List<StateResponse> stateresponse;
31 const HealthPolicyLayout({
32 Key key,
33 this.retailLoginResponse,
34 this.username,
35 this.password,
36 }) : super(key: key);
37 @override
38 _HealthPolicyLayoutState createState() => _HealthPolicyLayoutState(
39 retailLoginResponse: this.retailLoginResponse,
40 username: username,
41 password: password);
42}
43
44final GlobalKey<ScaffoldState> healthPolicyScaffoldKey =
45 new GlobalKey<ScaffoldState>();
46
47class _HealthPolicyLayoutState extends State<HealthPolicyLayout> {
48 String username, password;
49 bool isLoadingPremium;
50 RetailLoginResponse retailLoginResponse;
51 // List<StateResponse> stateresponse;
52 _HealthPolicyLayoutState(
53 {this.retailLoginResponse, this.username, this.password});
54
55 static List<HealthProductEntity> _productNames = [];
56 int _currVal = 1;
57 String _currText;
58
59//Initial static Product List
60
61 List<HealthProductEntity> _healthProductsAvailable = [];
62
63 HealthplanBloc healthplanBloc;
64 HealthBoosterPlan healthBoosterPlan;
65
66//TODO:Implement the function;
67//Function to generate the _products_Available list from the loginResponse api
68 List healthProductGenerator(RetailLoginResponse response) {
69 int index = 0;
70 Map<String, bool> healthProducts =
71 response.mappedProduct.health.healthChiSubProducts;
72 Health healthResponse = response.mappedProduct.health;
73 print('The length is : ${_healthProductsAvailable.length}');
74//Filter out thr HealthPorductList from the api reponse
75 /////////Danger is here ------remove the do-undo the ! sign in response,mappedProduct.health.isHealthCHIMapped
76 if (!response.mappedProduct.health.isHealthChiMapped) {
77 _healthProductsAvailable.removeRange(0, 5);
78 }
79
80 if (response.mappedProduct.health.isHealthChiMapped) {
81 Map<String, bool> healthProducts =
82 response.mappedProduct.health.healthChiSubProducts;
83 if (!healthProducts['Visible_HealthProtect'])
84 _healthProductsAvailable.removeAt(0);
85 if (!healthProducts['Visible_HelathProtectPlus'])
86 _healthProductsAvailable.removeAt(0);
87 if (!healthProducts['Visible_HealthSecure'])
88 _healthProductsAvailable.removeAt(0);
89 if (!healthProducts['Visible_HealthSecurePlus'])
90 _healthProductsAvailable.removeAt(0);
91 if (!healthProducts['Visible_iHealth'])
92 _healthProductsAvailable.removeAt(0);
93 }
94 if (!healthResponse.isHospifundMapped)
95 _healthProductsAvailable.removeLast();
96 if (!healthResponse.isHealthPpapMapped)
97 _healthProductsAvailable.removeWhere((item) => item.id == 21);
98 if (!healthResponse.isHealthBoosterMapped)
99 _healthProductsAvailable.removeWhere((item) => item.id == 19);
100
101 print(_healthProductsAvailable);
102
103 return _healthProductsAvailable;
104 }
105
106 @override
107 void initState() {
108 // TODO: implement initState
109 super.initState();
110 print(retailLoginResponseToJson(retailLoginResponse));
111 isLoadingPremium = false;
112 _healthProductsAvailable = [
113 HealthProductEntity(
114 title: 'Health Protect',
115 id: 14,
116 healthplanEvent: HealthProtectEvent(
117 // userId: retailLoginResponse.agentId.toString(),
118 userId: retailLoginResponse.agentId.toString(),
119 password: password,
120 subType: 14.toString(),
121 userName: username),
122 ),
123 HealthProductEntity(
124 title: 'Health Protect Plus',
125 id: 12,
126 healthplanEvent: HealthProtectPlusEvent(
127 userId: retailLoginResponse.agentId.toString(),
128 password: password,
129 subType: 12.toString(),
130 userName: username)),
131 HealthProductEntity(
132 title: 'Health Smart',
133 id: 16,
134 healthplanEvent: HealthSmartEvent(
135 userId: retailLoginResponse.agentId.toString(),
136 password: password,
137 subType: 16.toString(),
138 userName: username)),
139 HealthProductEntity(
140 title: 'Health Smart Plus',
141 id: 15,
142 healthplanEvent: HealthSmartPlusEvent(
143 userId: retailLoginResponse.agentId.toString(),
144 password: password,
145 subType: 15.toString(),
146 userName: username)),
147 HealthProductEntity(
148 title: 'iHealth', id: 17, healthplanEvent: IHealthEvent()),
149 HealthProductEntity(
150 title: 'Health Booster',
151 id: 19,
152 healthplanEvent: HealthBoosterEvent(
153 userId: retailLoginResponse.agentId.toString(),
154 password: password,
155 subType: 19.toString(),
156 userName: username,
157 healthBoosterPlan: healthBoosterPlan,
158 )),
159 HealthProductEntity(title: 'PPAP', id: 21, healthplanEvent: PPAPEvent()),
160 HealthProductEntity(
161 title: 'Hospifund', id: 25, healthplanEvent: HospifundEvent()),
162 ];
163 print(this.retailLoginResponse);
164 _productNames = healthProductGenerator(this.retailLoginResponse);
165 print('_productNames $_productNames');
166
167 //IF NO health products are mapped , then show error or else, continue the flow of app
168
169 if (_productNames.length == 0) {
170 setState(() {
171 Constants.showWordingsButton = false;
172 });
173 PlatformAlertDialog(
174 title: 'ICICI Lombard',
175 content: 'Please try again',
176 defaultActionText: 'Ok',
177 action: PlatformAlertDialogAction(
178 child: Text('Ok'),
179 onPressed: () {
180 Navigator.of(context).pop();
181 },
182 )).show(context);
183 } else {
184 print('The products are: $_productNames');
185 _currText = _productNames[0].title;
186 print('_currtext $_currText');
187 triggerInitialHealthPolicyState(_currText, retailLoginResponse);
188 healthplanBloc = HealthplanBloc();
189 }
190 }
191
192 void updateisLoadingPremium(bool newStatus) {
193 setState(() {
194 isLoadingPremium = newStatus;
195 });
196 }
197
198 @override
199 Widget build(BuildContext context) {
200 return BlocBuilder<HealthplanBloc, HealthplanState>(
201 bloc: healthplanBloc,
202 builder: (context, state) {
203 return Stack(
204 children: <Widget>[
205 Scaffold(
206 key: healthPolicyScaffoldKey,
207 drawer: Theme(
208 data: Theme.of(context).copyWith(
209 canvasColor: Colors.transparent,
210 ),
211 child: AppDrawer(),
212 ),
213 appBar: CustomAppBar(
214 appDrawerFunction: () =>
215 healthPolicyScaffoldKey.currentState.openDrawer(),
216 customDrawerIcon: false,
217 title: Text(
218 'Quick Quote',
219 style: CustomTextStyles.appBarTextStyle,
220 ),
221 actions: <Widget>[],
222 ),
223 body: BlocBuilder<HealthplanBloc, HealthplanState>(
224 builder: (context, state) {
225 return SafeArea(
226 child: Stack(
227 children: <Widget>[
228 backgroundImage(),
229 SingleChildScrollView(
230 scrollDirection: Axis.vertical,
231 child: Padding(
232 padding:
233 EdgeInsets.only(left: 10, right: 10, top: 5),
234 child: Container(
235 width: SizeConfig.blockSizeHorizontal * 98,
236 decoration: BoxDecoration(
237 shape: BoxShape.rectangle,
238
239 // border: Border(
240 // top: BorderSide(width: 5,color: Colors.white.withOpacity(0.1)),
241 // right: BorderSide(width: 5,color: Colors.redAccent.withOpacity(0.5)),
242 // bottom: BorderSide(width: 5,color: Colors.redAccent.withOpacity(0.5)),
243 // left: BorderSide(width: 5,color: Colors.white.withOpacity(0.1)
244 // )
245 // ),
246 // borderRadius: BorderRadius.all(10),
247 // borderRadius: BorderRadius.only(bottomLeft: Radius.circular()),
248 color: Colors.white.withOpacity(0.4),
249 ),
250 child: Column(
251 mainAxisSize: MainAxisSize.min,
252 crossAxisAlignment: CrossAxisAlignment.start,
253 children: <Widget>[
254 //The DropDown (with Heading) to select HealthProduct
255 productSelector(),
256 SizedBox(
257 height: 5.0,
258 ),
259//----------------The health policy parameters according to the product name wil go here
260 // (state is HealthplanInitialState)
261 // ? Center(
262 // child: Container(
263 // height: 200,
264 // width: double.infinity,
265 // child: Center(
266 // child: CircularProgressIndicator(),
267 // ),
268 // ),
269 // )
270 // : (state is HealthProtectState)
271 // ? HealthProtectQuotation(
272 // healthPlanMasterResponse:
273 // state.response,
274 // retailLoginResponse:
275 // retailLoginResponse,
276 // )
277 // : (state is HealthProtectPlusState)
278 // ? Text('Health Protect Plus State')
279 // : CircularProgressIndicator()
280 getMainWidget(state),
281 ],
282 ),
283 ),
284 ),
285 ),
286 ],
287 ),
288 );
289 }),
290 floatingActionButton: FloatingActionButton(
291 mini: true,
292 child: Container(
293 decoration: BoxDecoration(
294 color: Color(0xff063b6d),
295 shape: BoxShape.circle,
296 image: DecorationImage(
297 image: AssetImage(
298 'assets/images/info.png',
299 ),
300 fit: BoxFit.fill)),
301 ),
302 onPressed: () {
303 healthProtect_Wording(context);
304 },
305 ),
306 //
307 ),
308 if (isLoadingPremium) Transparentloader(),
309 ],
310 );
311 });
312 }
313
314 Widget getMainWidget(HealthplanState state) {
315 if (state is HealthplanInitialState)
316 return Center(
317 child: Container(
318 height: 200,
319 width: double.infinity,
320 child: Center(
321 child: CircularProgressIndicator(
322 backgroundColor: Colors.deepPurple,
323 ),
324 ),
325 ),
326 );
327 else if (state is HealthProtectState)
328 return HealthProtectQuotation(
329 healthPlanMasterResponse: state.response,
330 retailLoginResponse: retailLoginResponse,
331 );
332 else if (state is HealthProtectPlusState)
333 return HealthQuotationCommon(
334 healthPlanMasterResponse: state.response,
335 retailLoginResponse: retailLoginResponse,
336 healthQuotationOptions: HealthQuotationOptions.HealthProtectPlus,
337 username: state.username,
338 password: state.password,
339 showLoader: updateisLoadingPremium,
340 );
341 else if (state is HealthSmartState)
342 return HealthQuotationCommon(
343 healthPlanMasterResponse: state.response,
344 retailLoginResponse: retailLoginResponse,
345 healthQuotationOptions: HealthQuotationOptions.HealthSmart,
346 username: state.username,
347 password: state.password,
348 showLoader: updateisLoadingPremium,
349 );
350 else if (state is HealthSmartPlusState)
351 return HealthQuotationCommon(
352 healthPlanMasterResponse: state.response,
353 retailLoginResponse: retailLoginResponse,
354 healthQuotationOptions: HealthQuotationOptions.HealthSmartPlus,
355 username: state.username,
356 password: state.password,
357 showLoader: updateisLoadingPremium,
358 );
359 else if (state is HealthBoosterState) {
360 return Column(
361 children: <Widget>[
362 Padding(
363 padding: EdgeInsets.symmetric(horizontal: 15),
364 child: Column(
365 mainAxisSize: MainAxisSize.min,
366 crossAxisAlignment: CrossAxisAlignment.start,
367 children: <Widget>[
368 SizedBox(
369 height: 10,
370 ),
371 Text(
372 "Sub-Type",
373 style: CustomTextStyles.policyDetailHeadingTextStyle,
374 ),
375 SizedBox(
376 height: 10,
377 ),
378 Container(
379 height: 30,
380 width: double.infinity,
381 child: ListView(
382 scrollDirection: Axis.horizontal,
383 children: <Widget>[
384 InkWell(
385 //highlightColor: Colors.red,
386 splashColor: Colors.blueAccent,
387 onTap: () {
388 setState(() {
389 healthBoosterPlan = HealthBoosterPlan.TopUpPlan;
390 });
391 BlocProvider.of<HealthplanBloc>(context)
392 .add(HealthBoosterEvent(
393 userId: retailLoginResponse.agentId.toString(),
394 password: password,
395 subType: 19.toString(),
396 userName: username,
397 healthBoosterPlan: healthBoosterPlan,
398 ));
399 },
400 child: RadioItem(
401 RadioWidgetModel(
402 isSelected: healthBoosterPlan ==
403 HealthBoosterPlan.TopUpPlan,
404 text: "Top Up Plan",
405 ),
406 ),
407 ),
408 InkWell(
409 //highlightColor: Colors.red,
410 splashColor: Colors.blueAccent,
411 onTap: () {
412 setState(() {
413 healthBoosterPlan =
414 HealthBoosterPlan.SuperTopUpPlan;
415 });
416 BlocProvider.of<HealthplanBloc>(context)
417 .add(HealthBoosterEvent(
418 userId: retailLoginResponse.agentId.toString(),
419 password: password,
420 subType: 20.toString(),
421 userName: username,
422 healthBoosterPlan: healthBoosterPlan,
423 ));
424 },
425 child: RadioItem(
426 RadioWidgetModel(
427 isSelected: healthBoosterPlan ==
428 HealthBoosterPlan.SuperTopUpPlan,
429 text: "Super Top Up Plan",
430 ),
431 ),
432 ),
433 ],
434 ),
435 ),
436 ],
437 ),
438 ),
439 HealthQuotationCommon(
440 healthPlanMasterResponse: state.response,
441 retailLoginResponse: retailLoginResponse,
442 healthQuotationOptions: HealthQuotationOptions.HealthBooster,
443 username: state.username,
444 password: state.password,
445 showLoader: updateisLoadingPremium,
446 healthBoosterPlan: healthBoosterPlan,
447 ),
448 ],
449 );
450 } else if (state is PPAPState)
451 return PpapQuotation();
452 else
453 return CircularProgressIndicator();
454 }
455
456 Widget productSelector() {
457 return Column(
458 crossAxisAlignment: CrossAxisAlignment.start,
459 children: <Widget>[
460 Padding(
461 padding: EdgeInsets.only(left: 20, top: 10),
462 child: Text(
463 'Product Name',
464 style: TextStyle(color: Color(0xffb01f21)),
465 ),
466 ),
467 Padding(
468 padding: EdgeInsets.only(left: 20, top: 10, right: 50),
469 child: GestureDetector(
470 child: Container(
471 color: Colors.transparent,
472 child: Row(
473 mainAxisAlignment: MainAxisAlignment.spaceBetween,
474 children: <Widget>[
475 Text(
476 '$_currText',
477 style:
478 TextStyle(fontWeight: FontWeight.bold, fontSize: 16.5),
479 ),
480 Icon(Icons.keyboard_arrow_down),
481 ],
482 ),
483 ),
484 onTap: () async {
485 String productName = await showDialog(
486 barrierDismissible: false,
487 context: context,
488 builder: (BuildContext context) {
489 return AlertDialog(
490 shape: RoundedRectangleBorder(
491 borderRadius: BorderRadius.all(Radius.circular(20.0))),
492 title: Center(child: Text('Select Health Product')),
493 content: StatefulBuilder(
494 builder: (context, setState) {
495 return Column(
496 mainAxisSize: MainAxisSize.min,
497 children: _productNames.map((product) {
498 return RadioListTile(
499 controlAffinity: ListTileControlAffinity.trailing,
500 selected: false,
501 title: Text('${product.title}'),
502 groupValue: _currVal,
503 value: product.id,
504 onChanged: (val) {
505 setState(() {
506 healthBoosterPlan =
507 HealthBoosterPlan.TopUpPlan;
508 _currVal = val;
509 });
510 print(healthBoosterPlan);
511 print('Selected this: ${product.title}');
512
513 BlocProvider.of<HealthplanBloc>(context)
514 .add(product.healthplanEvent);
515 Navigator.of(context).pop(product.title);
516 },
517 );
518 }).toList(),
519 );
520 },
521 ),
522 );
523 },
524 );
525 setState(() {
526 _currText =
527 (productName != null) ? productName : 'Health Protect';
528 print('selected value: $productName');
529 });
530 },
531 ),
532 ),
533 ],
534 );
535 }
536
537//Triggers an event change on Tapping the healthPRoduct list and optionally returns the event
538 HealthplanEvent triggerInitialHealthPolicyState(
539 String caseText, RetailLoginResponse retailLoginResponse) {
540 switch (caseText) {
541 case "Health Protect Plus":
542 {
543 print('Triggerring');
544 BlocProvider.of<HealthplanBloc>(context).add(HealthProtectPlusEvent(
545 userId: retailLoginResponse.agentId.toString(),
546 password: password,
547 subType: "12",
548 userName: username));
549 return HealthProtectPlusEvent(
550 userId: retailLoginResponse.agentId.toString(),
551 password: password,
552 subType: "12",
553 userName: username);
554 }
555 break;
556 case "Health Secure":
557 {
558 BlocProvider.of<HealthplanBloc>(context).add(HealthSecureEvent());
559 return HealthSecureEvent();
560 }
561 break;
562 case "Health Secure Plus":
563 {
564 BlocProvider.of<HealthplanBloc>(context).add(HealthSecurePlusEvent());
565 return HealthSecurePlusEvent();
566 }
567 break;
568 case "Health Protect":
569 {
570 BlocProvider.of<HealthplanBloc>(context).add(HealthProtectEvent(
571 userId: retailLoginResponse.agentId.toString(),
572 password: password,
573 subType: "14",
574 userName: username));
575 return HealthProtectEvent(
576 userId: retailLoginResponse.agentId.toString(),
577 password: password,
578 subType: "14",
579 userName: username);
580 }
581 break;
582 case "Health Smart":
583 {
584 BlocProvider.of<HealthplanBloc>(context).add(HealthSmartEvent(
585 userId: retailLoginResponse.agentId.toString(),
586 password: password,
587 subType: "16",
588 userName: username,
589 ));
590 return HealthSmartEvent(
591 userId: retailLoginResponse.agentId.toString(),
592 password: password,
593 subType: "16",
594 userName: username,
595 );
596 }
597 break;
598 case "Health Smart Plus":
599 {
600 BlocProvider.of<HealthplanBloc>(context).add(HealthSmartPlusEvent(
601 userId: retailLoginResponse.agentId.toString(),
602 password: password,
603 subType: "15",
604 userName: username,
605 ));
606 return HealthSmartPlusEvent(
607 userId: retailLoginResponse.agentId.toString(),
608 password: password,
609 subType: "15",
610 userName: username,
611 );
612 }
613 break;
614 case "i Health":
615 {
616 BlocProvider.of<HealthplanBloc>(context).add(IHealthEvent());
617 return IHealthEvent();
618 }
619 break;
620 case "Health Booster":
621 {
622 BlocProvider.of<HealthplanBloc>(context).add(HealthBoosterEvent(
623 userId: retailLoginResponse.agentId.toString(),
624 password: password,
625 subType: "19",
626 userName: username,
627 healthBoosterPlan: healthBoosterPlan,
628 ));
629 return HealthBoosterEvent(
630 userId: retailLoginResponse.agentId.toString(),
631 password: password,
632 subType: "19",
633 userName: username,
634 healthBoosterPlan: healthBoosterPlan,
635 );
636 }
637 break;
638 case "PPAP":
639 {
640 BlocProvider.of<HealthplanBloc>(context).add(PPAPEvent());
641 return PPAPEvent();
642 }
643 break;
644 case "Hospifund":
645 {
646 BlocProvider.of<HealthplanBloc>(context).add(HospifundEvent());
647 return HospifundEvent();
648 }
649 break;
650 }
651 }
652}