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