import 'package:diplomaticquarterapp/core/service/insurance_service.dart'; import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart'; import 'package:diplomaticquarterapp/locator.dart'; import 'package:diplomaticquarterapp/models/insurance/getInsuranceCompaniesModel.dart'; import 'package:diplomaticquarterapp/pages/medical/balance/new_text_Field.dart'; import 'package:diplomaticquarterapp/theme/colors.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart'; import 'package:diplomaticquarterapp/widgets/dialogs/radio_selection_dialog.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; class UpdateInsuranceManually extends StatefulWidget { const UpdateInsuranceManually({Key key}) : super(key: key); @override State createState() => _UpdateInsuranceManuallyState(); } class _UpdateInsuranceManuallyState extends State { TextEditingController _nationalIDTextController = TextEditingController(); TextEditingController _cardHolderNameTextController = TextEditingController(); TextEditingController _membershipNoTextController = TextEditingController(); TextEditingController _policyNoTextController = TextEditingController(); ProjectViewModel projectViewModel; InsuranceCardService _insuranceCardService = locator(); List insuranceCompaniesList = []; int _selectedInsuranceCompanyIndex = -1; InsuranceCompaniesGetModel selectedInsuranceCompanyObj; @override void initState() { WidgetsBinding.instance.addPostFrameCallback((_) { getInsuranceCompanies(); }); super.initState(); } @override Widget build(BuildContext context) { projectViewModel = Provider.of(context); _nationalIDTextController.text = projectViewModel.user.patientIdentificationNo; return AppScaffold( isShowAppBar: true, isShowDecPage: false, appBarTitle: TranslationBase.of(context).updateInsurCards, showNewAppBar: true, showNewAppBarTitle: true, backgroundColor: CustomColors.appBackgroudGreyColor, body: SingleChildScrollView( child: Padding( padding: EdgeInsets.all(21), child: Column( crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( TranslationBase.of(context).enterInsuranceDetails, textAlign: TextAlign.center, style: TextStyle( fontSize: 16, letterSpacing: -0.48, fontWeight: FontWeight.w600, ), ), SizedBox(height: 12), InkWell( onTap: () { confirmSelectInsuranceCompanyDialog(); }, child: Container( padding: EdgeInsets.all(8), width: double.infinity, height: 65, decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), color: Colors.white), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( selectedInsuranceCompanyObj != null ? selectedInsuranceCompanyObj.companyName : TranslationBase.of(context).insuranceCompany, style: TextStyle( fontSize: 14, fontWeight: FontWeight.w600, letterSpacing: -0.46, ), ), Icon(Icons.arrow_drop_down) ], ), ), ), SizedBox(height: 12), NewTextFields( hintText: TranslationBase.of(context).nationalIdNumber, controller: _nationalIDTextController, readOnly: true, ), SizedBox(height: 12), NewTextFields( hintText: TranslationBase.of(context).cardHolderName, controller: _cardHolderNameTextController, readOnly: false, ), SizedBox(height: 12), NewTextFields( hintText: TranslationBase.of(context).membershipNo, controller: _membershipNoTextController, readOnly: false, ), SizedBox(height: 12), NewTextFields( hintText: TranslationBase.of(context).insurancePolicyNo, controller: _policyNoTextController, readOnly: false, ), SizedBox(height: 12), InkWell( onTap: () { List list = [ RadioSelectionDialogModel(TranslationBase.of(context).myAccount, 0), RadioSelectionDialogModel(TranslationBase.of(context).myFamilyFiles, 1), RadioSelectionDialogModel(TranslationBase.of(context).otherAccount, 2), ]; showDialog( context: context, builder: (cxt) => RadioSelectionDialog( listData: list, // selectedIndex: // beneficiaryType == BeneficiaryType.MyAccount ? 0 : (beneficiaryType == BeneficiaryType.MyFamilyFiles ? 1 : (beneficiaryType == BeneficiaryType.OtherAccount ? 2 : -1)), onValueSelected: (index) { var type; if (index == 0) { // type = BeneficiaryType.MyAccount; } else if (index == 1) { // type = BeneficiaryType.MyFamilyFiles; } else { // type = BeneficiaryType.OtherAccount; } setState(() {}); }, ), ); }, child: Container( padding: EdgeInsets.all(8), width: double.infinity, height: 65, decoration: BoxDecoration(borderRadius: BorderRadius.circular(12), color: Colors.white), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( TranslationBase.of(context).insuranceClassName, style: TextStyle( fontSize: 14, fontWeight: FontWeight.w600, letterSpacing: -0.46, ), ), Icon(Icons.arrow_drop_down) ], ), ), ), ], ), ), ), bottomSheet: Container( color: Theme.of(context).scaffoldBackgroundColor, padding: EdgeInsets.all(18), child: DefaultButton(TranslationBase.of(context).submit, () {}), ), ); } void confirmSelectInsuranceCompanyDialog() { List list = [ for (int i = 0; i < insuranceCompaniesList.length; i++) RadioSelectionDialogModel(insuranceCompaniesList[i].companyName, i), ]; showDialog( context: context, builder: (cxt) => RadioSelectionDialog( listData: list, selectedIndex: _selectedInsuranceCompanyIndex, isScrollable: true, onValueSelected: (index) { _selectedInsuranceCompanyIndex = index; selectedInsuranceCompanyObj = insuranceCompaniesList[index]; setState(() {}); getInsuranceScheme(); }, ), ); } void getInsuranceCompanies() { GifLoaderDialogUtils.showMyDialog(context); _insuranceCardService.getInsuranceCompanies().then((value) { value.forEach((result) { insuranceCompaniesList.add(InsuranceCompaniesGetModel.fromJson(result)); }); GifLoaderDialogUtils.hideDialog(context); }); } void getInsuranceScheme() { GifLoaderDialogUtils.showMyDialog(context); _insuranceCardService.getInsuranceSchemes(selectedInsuranceCompanyObj.projectID, selectedInsuranceCompanyObj.companyID).then((value) { value.forEach((result) { insuranceCompaniesList.add(InsuranceCompaniesGetModel.fromJson(result)); }); GifLoaderDialogUtils.hideDialog(context); }); } }