· 6 years ago · Mar 12, 2020, 09:38 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/widgets/constants.dart';
14import 'package:ipartneragent/widgets/custom_gradient_flat_button.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';
20
21import 'package:ipartneragent/utilities/Custom_TextStyles.dart';
22import 'package:ipartneragent/utilities/size_config.dart';
23import 'package:ipartneragent/widgets/CustomAppBar.dart';
24import 'package:ipartneragent/widgets/transparent_loader.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}
44
45final GlobalKey<ScaffoldState> healthPolicyScaffoldKey =
46 new GlobalKey<ScaffoldState>();
47
48class _HealthPolicyLayoutState extends State<HealthPolicyLayout> {
49 String username, password;
50
51 RetailLoginResponse retailLoginResponse;
52 // List<StateResponse> stateresponse;
53 _HealthPolicyLayoutState(
54 {this.retailLoginResponse, this.username, this.password});
55
56 static List<HealthProductEntity> _productNames = [];
57 int _currVal = 1;
58 String _currText;
59bool showFab = true;
60//Initial static Product List
61
62 List<HealthProductEntity> _healthProductsAvailable = [];
63
64 HealthplanBloc healthplanBloc;
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();
110print(retailLoginResponseToJson(retailLoginResponse));
111 _healthProductsAvailable = [
112 HealthProductEntity(
113 title: 'Health Protect',
114 id: 14,
115 healthplanEvent: HealthProtectEvent(
116 // userId: retailLoginRsponse.agentId.toString(),
117 userId: retailLoginResponse.agentId.toString(),
118 password: password,
119 subType: 14.toString(),
120 userName: username),
121 ),
122 HealthProductEntity(
123 title: 'Health Protect Plus',
124 id: 12,
125 healthplanEvent: HealthProtectPlusEvent(
126 userId: retailLoginResponse.agentId.toString(),
127 password: password,
128 subType: 12.toString(),
129 userName: username
130 )),
131 HealthProductEntity(
132 title: 'Health Smart', id: 16, healthplanEvent: HealthSmartEvent(
133 userId: retailLoginResponse.agentId.toString(),
134 password: password,
135 subType: 16.toString(),
136 userName: username
137 )),
138 HealthProductEntity(
139 title: 'Health Smart Plus',
140 id: 15,
141 healthplanEvent: HealthSmartPlusEvent(
142 userId: retailLoginResponse.agentId.toString(),
143 password: password,
144 subType: 15.toString(),
145 userName: username
146 )),
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 )),
158 HealthProductEntity(title: 'PPAP', id: 21, healthplanEvent: PPAPEvent()),
159 HealthProductEntity(
160 title: 'Hospifund', id: 25, healthplanEvent: HospifundEvent()),
161 ];
162 print(this.retailLoginResponse);
163 _productNames = healthProductGenerator(this.retailLoginResponse);
164 print('_productNames $_productNames');
165
166 //IF NO health products are mapped , then show error or else, continue the flow of app
167
168 if(_productNames.length == 0){
169 setState(() {
170 Constants.showWordingsButton = false;
171 });
172 PlatformAlertDialog(
173 title: 'ICICI Lombard',
174 content: 'Please try again',
175 defaultActionText: 'Ok',
176 action: PlatformAlertDialogAction(
177 child: Text('Ok'),
178 onPressed: () {
179 Navigator.of(context).pop();
180 },
181 )).show(context);
182 }else{
183 print('The products are: $_productNames');
184 _currText = _productNames[0].title;
185 print('_currtext $_currText');
186 triggerInitialHealthPolicyState(_currText, retailLoginResponse);
187 healthplanBloc = HealthplanBloc();
188 }
189
190 }
191
192 Widget getMainWidget(HealthplanState state) {
193 if (state is HealthplanInitialState)
194 return showInititalWidget();
195 else if (state is HealthProtectState)
196 return HealthProtectQuotation(
197 healthPlanMasterResponse: state.response,
198 retailLoginResponse: retailLoginResponse,
199 );
200 else if (state is HealthProtectPlusState)
201 return HealthQuotationCommon(
202 healthPlanMasterResponse: state.response,
203 retailLoginResponse: retailLoginResponse,
204 healthQuotationOptions: HealthQuotationOptions.HealthProtectPlus,
205 );
206 else if (state is HealthSmartState)
207 return HealthQuotationCommon(
208 healthPlanMasterResponse: state.response,
209 retailLoginResponse: retailLoginResponse,
210 healthQuotationOptions: HealthQuotationOptions.HealthSmart,
211 );
212 else if (state is HealthSmartPlusState)
213 return HealthQuotationCommon(
214 healthPlanMasterResponse: state.response,
215 retailLoginResponse: retailLoginResponse,
216 healthQuotationOptions: HealthQuotationOptions.HealthSmartPlus,
217 );
218 else if (state is HealthBoosterState)
219 return HealthQuotationCommon(
220 healthPlanMasterResponse: state.response,
221 retailLoginResponse: retailLoginResponse,
222 healthQuotationOptions: HealthQuotationOptions.HealthBooster,
223 );
224 else if (state is PPAPState)
225 return CircularProgressIndicator();
226 else
227 return CircularProgressIndicator();
228 }
229
230
231 @override
232 Widget build(BuildContext context) {
233 return BlocBuilder<HealthplanBloc, HealthplanState>(
234 bloc: healthplanBloc,
235 builder: (context, state) {
236 return Scaffold(
237 key: healthPolicyScaffoldKey,
238 drawer: Theme(
239 data: Theme.of(context).copyWith(
240 canvasColor: Colors.transparent,
241 ),
242 child: AppDrawer(),
243 ),
244 appBar: CustomAppBar(
245 appDrawerFunction: () =>
246 healthPolicyScaffoldKey.currentState.openDrawer(),
247 customDrawerIcon: false,
248 title: Text(
249 'Quick Quote',
250 style: CustomTextStyles.appBarTextStyle,
251 ),
252 actions: <Widget>[],
253 ),
254 body: BlocBuilder<HealthplanBloc, HealthplanState>(
255 builder: (context, state) {
256 return SafeArea(
257 child: Stack(
258 children: <Widget>[
259 backgroundImage(),
260 SingleChildScrollView(
261 scrollDirection: Axis.vertical,
262 child: Padding(
263 padding: EdgeInsets.only(left: 10, right: 10, top: 5),
264 child: Container(
265 width: SizeConfig.blockSizeHorizontal * 98,
266
267 decoration: BoxDecoration(
268 shape: BoxShape.rectangle,
269 borderRadius: BorderRadius.circular(10),
270
271 // border: Border(
272 // top: BorderSide(width: 5,color: Colors.white.withOpacity(0.1)),
273 // right: BorderSide(width: 5,color: Colors.redAccent.withOpacity(0.5)),
274 // bottom: BorderSide(width: 5,color: Colors.redAccent.withOpacity(0.5)),
275 // left: BorderSide(width: 5,color: Colors.white.withOpacity(0.1)
276 // )
277 // ),
278 // borderRadius: BorderRadius.all(10),
279 // borderRadius: BorderRadius.only(bottomLeft: Radius.circular()),
280 color: Colors.white.withOpacity(0.4),
281 ),
282 child: Column(
283 mainAxisSize: MainAxisSize.max,
284 crossAxisAlignment: CrossAxisAlignment.start,
285 children: <Widget>[
286 //The DropDown (with Heading) to select HealthProduct
287 (_productNames.isEmpty) ? Container() : productSelector(),
288 SizedBox(
289 height: 5.0,
290 ),
291//----------------The health policy parameters according to the product name wil go here
292 getMainWidget(state)
293 ],
294 ),
295 ),
296 ),
297 ),
298 ],
299 ),
300 );
301 }),
302 floatingActionButton: ( Constants.showWordingsButton) ? FloatingActionButton(
303 mini: true,
304 child: Container(
305 decoration: BoxDecoration(
306 color: Color(0xff063b6d),
307 shape: BoxShape.circle,
308 image: DecorationImage(
309 image: AssetImage(
310 'assets/images/info.png',
311 ),
312 fit: BoxFit.fill)),
313 ),
314 onPressed: () {
315 healthProtect_Wording(context);
316 },
317 ) :Container(),
318 //
319 );
320 });
321 }
322
323
324 Widget showInititalWidget(){
325 return Center(
326 child: (_productNames.isEmpty) ?
327 Padding(
328 padding: const EdgeInsets.all(8.0),
329 child: Material(
330 color: Colors.black.withAlpha(7),
331 elevation: 0,
332 child: Container(
333 color: Colors.transparent,
334 height: 600,
335 width: double.infinity,
336 child: PlatformAlertDialog(
337 title: "ICICI Lombard",
338 defaultActionText: "OK",
339 content: "No health Products Could be mapped ... Please Try again Later",
340 action: PlatformAlertDialogAction(
341 onPressed: ()=>Navigator.pop(context),
342 child: Text('OK'),
343 ),
344 ),
345 ),
346 ),
347 ):Container(
348 height: 500,
349 child:Center(child: CircularProgressIndicator())
350 ),
351 );
352 }
353
354
355 Widget productSelector() {
356 return Column(
357 crossAxisAlignment: CrossAxisAlignment.start,
358 children: <Widget>[
359 Padding(
360 padding: EdgeInsets.only(left: 20, top: 10),
361 child: Text(
362 'Product Name',
363 style: TextStyle(color: Color(0xffb01f21)),
364 ),
365 ),
366 Padding(
367 padding: EdgeInsets.only(left: 20, top: 10, right: 50),
368 child: GestureDetector(
369 child: Container(
370 color: Colors.transparent,
371 child: Row(
372 mainAxisAlignment: MainAxisAlignment.spaceBetween,
373 children: <Widget>[
374 Text(
375 '$_currText',
376 style:
377 TextStyle(fontWeight: FontWeight.bold, fontSize: 16.5),
378 ),
379 Icon(Icons.keyboard_arrow_down),
380 ],
381 ),
382 ),
383 onTap: () async {
384 String productName = await showDialog(
385 barrierDismissible: false,
386 context: context,
387 builder: (BuildContext context) {
388 return AlertDialog(
389 shape: RoundedRectangleBorder(
390 borderRadius: BorderRadius.all(Radius.circular(20.0))),
391 title: Center(child: Text('Select Health Product')),
392 content: StatefulBuilder(
393 builder: (context, setState) {
394 return Column(
395 mainAxisSize: MainAxisSize.min,
396 children: _productNames.map((product) {
397 return RadioListTile(
398 controlAffinity: ListTileControlAffinity.trailing,
399 selected: false,
400 title: Text('${product.title}'),
401 groupValue: _currVal,
402 value: product.id,
403 onChanged: (val) {
404 setState(() {
405 _currVal = val;
406 });
407 print('Selected this: ${product.title}');
408
409 BlocProvider.of<HealthplanBloc>(context)
410 .add(product.healthplanEvent);
411 Navigator.of(context).pop(product.title);
412 },
413 );
414 }).toList(),
415 );
416 },
417 ),
418 );
419 },
420 );
421 setState(() {
422 _currText =
423 (productName != null) ? productName : 'Health Protect';
424 print('selected value: $productName');
425 });
426 },
427 ),
428 ),
429 ],
430 );
431 }
432
433//Triggers an event change on Tapping the healthPRoduct list and optionally returns the event
434 HealthplanEvent triggerInitialHealthPolicyState(
435 String caseText, RetailLoginResponse retailLoginResponse) {
436 switch (caseText) {
437 case "Health Protect Plus":
438 {
439 print('Triggerring');
440 BlocProvider.of<HealthplanBloc>(context)
441 .add(HealthProtectPlusEvent());
442 return HealthProtectPlusEvent();
443 }
444 break;
445 case "Health Secure":
446 {
447 BlocProvider.of<HealthplanBloc>(context).add(HealthSecureEvent());
448 return HealthSecureEvent();
449 }
450 break;
451 case "Health Secure Plus":
452 {
453 BlocProvider.of<HealthplanBloc>(context).add(HealthSecurePlusEvent());
454 return HealthSecurePlusEvent();
455 }
456 break;
457 case "Health Protect":
458 {
459 BlocProvider.of<HealthplanBloc>(context).add(HealthProtectEvent(
460 userId: retailLoginResponse.agentId.toString(),
461 password: password,
462 subType: "14",
463 userName: username));
464 return HealthProtectEvent(
465 userId: retailLoginResponse.agentId.toString(),
466 password: password,
467 subType: "14",
468 userName: username);
469 }
470 break;
471 case "Health Smart":
472 {
473 BlocProvider.of<HealthplanBloc>(context).add(HealthSmartEvent(
474 userId: retailLoginResponse.agentId.toString(),
475 password: password,
476 subType: "14",
477 userName: username,
478 ));
479 return HealthSmartEvent(
480 userId: retailLoginResponse.agentId.toString(),
481 password: password,
482 subType: "14",
483 userName: username,
484 );
485 }
486 break;
487 case "Health Smart Plus":
488 {
489 BlocProvider.of<HealthplanBloc>(context).add(HealthSmartPlusEvent(
490 userId: retailLoginResponse.agentId.toString(),
491 password: password,
492 subType: "14",
493 userName: username,
494 ));
495 return HealthSmartPlusEvent(
496 userId: retailLoginResponse.agentId.toString(),
497 password: password,
498 subType: "14",
499 userName: username,
500 );
501 }
502 break;
503 case "i Health":
504 {
505 BlocProvider.of<HealthplanBloc>(context).add(IHealthEvent());
506 return IHealthEvent();
507 }
508 break;
509 case "Health Booster":
510 {
511 BlocProvider.of<HealthplanBloc>(context).add(HealthBoosterEvent(
512 userId: retailLoginResponse.agentId.toString(),
513 password: password,
514 subType: "19",
515 userName: username,
516 ));
517 return HealthBoosterEvent(
518 userId: retailLoginResponse.agentId.toString(),
519 password: password,
520 subType: "19",
521 userName: username,
522 );
523 }
524 break;
525 case "PPAP":
526 {
527 BlocProvider.of<HealthplanBloc>(context).add(PPAPEvent());
528 return PPAPEvent();
529 }
530 break;
531 case "Hospifund":
532 {
533 BlocProvider.of<HealthplanBloc>(context).add(HospifundEvent());
534 return HospifundEvent();
535 }
536 break;
537 }
538 }
539}