import 'dart:convert';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:test_sa/controllers/validator/validator.dart';
import 'package:test_sa/extensions/context_extension.dart';
import 'package:test_sa/extensions/enum_extensions.dart';
import 'package:test_sa/extensions/int_extensions.dart';
import 'package:test_sa/extensions/string_extensions.dart';
import 'package:test_sa/extensions/text_extensions.dart';
import 'package:test_sa/extensions/widget_extensions.dart';
import 'package:test_sa/helper/utils.dart';
import 'package:test_sa/models/generic_attachment_model.dart';
import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/new_models/mapped_sites.dart';
import 'package:test_sa/models/new_models/task_request/task_type_model.dart';
import 'package:test_sa/models/new_models/traf_department.dart';
import 'package:test_sa/models/new_models/work_order_detail_model.dart';
import 'package:test_sa/models/service_request/supp_engineer_work_orders.dart';
import 'package:test_sa/models/service_request/supplier_details.dart';
import 'package:test_sa/modules/cm_module/cm_request_utils.dart';
import 'package:test_sa/modules/cm_module/views/components/action_button/footer_action_button.dart';
import 'package:test_sa/modules/loan_module/models/loan_form_model.dart';
import 'package:test_sa/modules/loan_module/provider/loan_period_provider.dart';
import 'package:test_sa/modules/loan_module/provider/loan_provider.dart';
import 'package:test_sa/modules/loan_module/provider/medical_department_provider.dart';
import 'package:test_sa/new_views/app_style/app_color.dart';
import 'package:test_sa/new_views/common_widgets/app_filled_button.dart';
import 'package:test_sa/new_views/common_widgets/app_text_form_field.dart';
import 'package:test_sa/new_views/common_widgets/single_item_drop_down_menu.dart';
import 'package:test_sa/providers/gas_request_providers/site_provider.dart';
import 'package:test_sa/providers/loading_list_notifier.dart';
import 'package:test_sa/providers/lookups/department_lookup_provider.dart';
import 'package:test_sa/providers/work_order/vendor_provider.dart';
import 'package:test_sa/views/widgets/images/multi_image_picker.dart';
import 'package:test_sa/views/widgets/item_views/info_header_widget.dart';
import 'package:test_sa/views/widgets/item_views/info_text_widget.dart';
import '../../../../../../new_views/common_widgets/default_app_bar.dart';

class CreateLoanRequestPage extends StatefulWidget {
  static const String id = "/create-loan";
  int? workOrderId;
  WorkOrderData? workOrder;

  CreateLoanRequestPage({Key? key, this.workOrderId, this.workOrder}) : super(key: key);

  @override
  _CreateLoanRequestPageState createState() => _CreateLoanRequestPageState();
}

class _CreateLoanRequestPageState extends State<CreateLoanRequestPage> with TickerProviderStateMixin {
  final List<GenericAttachmentModel> attachments = [];
  final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
  final GlobalKey<ScaffoldState> _scaffoldKey = GlobalKey<ScaffoldState>();
  TaskType? selectedType;
  final LoanFormModel _loanFormModel = LoanFormModel(isNewVendor: false);

  TextEditingController commentController = TextEditingController();
  TextEditingController vendorPhoneController = TextEditingController();
  TextEditingController vendorEmailController = TextEditingController();

  bool get isBackUpRequest => widget.workOrderId != null;

  List<Lookup> loanTypes = [];

  @override
  void initState() {
    super.initState();
    Provider.of<MedicalDepartmentProvider>(context, listen: false).reset();
    Provider.of<LoanPeriodProvider>(context, listen: false).reset();
    loanTypes = [Lookup(id: 0, name: "Standard", value: 1), Lookup(id: 1, name: "Backup", value: 2)];

    if (isBackUpRequest) {
      fillSiteDeptInfo();
    }
  }

  @override
  void dispose() {
    vendorPhoneController.dispose();
    vendorEmailController.dispose();
    super.dispose();
  }

  void fillSiteDeptInfo() {
    _loanFormModel.mappedSite = MappedSite.fromJson(widget.workOrder!.site!.toJson());
    _loanFormModel.mappedDepartment = TrafDepartment.fromJson(widget.workOrder!.department!.toJson());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      key: _scaffoldKey,
      appBar: DefaultAppBar(title: 'Loan Request'.addTranslation),
      body: Form(
        key: _formKey,
        child: Column(
          children: [
            SingleChildScrollView(
              padding: const EdgeInsets.all(16),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.min,
                children: [
                  SingleItemDropDownMenu<Lookup, NullableLoadingProvider>(
                    context: context,
                    title: "Loan Type",
                    enabled: false,
                    staticData: loanTypes,
                    initialValue: isBackUpRequest ? loanTypes[1] : loanTypes[0],
                    showShadow: false,
                    // backgroundColor: AppColor.fieldBgColor(context),
                    showAsBottomSheet: true,
                    onSelect: (value) {},
                  ),
                  16.height,
                  if (isBackUpRequest) ...[
                    InfoHeaderWidget('Asset Information'.addTranslation),
                    8.height,
                    InfoTextWidget(label: context.translation.assetName, value: widget.workOrder!.assetNdModel!.name?.cleanupWhitespace.capitalizeFirstOfEach ?? '-'),
                    // Text(
                    //   '${context.translation.assetName}: ${widget.workOrder!.assetNdModel!.name?.cleanupWhitespace.capitalizeFirstOfEach}',
                    //   style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    // ),
                    InfoTextWidget(label: context.translation.assetNumber,value:widget.workOrder!.asset!.assetNumber ,),
                    // Text(
                    //   '${context.translation.assetNumber}:  ${widget.workOrder!.asset!.assetNumber}',
                    //   style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    // ),
                    InfoTextWidget(label: context.translation.serialNo,value:widget.workOrder!.asset!.assetSerialNo ,),
                    InfoTextWidget(label: context.translation.model,value:widget.workOrder!.model?.name!.cleanupWhitespace.capitalizeFirstOfEach,),
                    InfoTextWidget(label: context.translation.manufacture,value:widget.workOrder!.manufacturer?.name?.cleanupWhitespace.capitalizeFirstOfEach),

                    // Text(
                    //   '${context.translation.serialNo}:  ${widget.workOrder!.asset!.assetSerialNo}',
                    //   style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    // ),
                    // Text(
                    //   '${context.translation.model}: ${widget.workOrder!.model?.name!.cleanupWhitespace.capitalizeFirstOfEach}',
                    //   style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    // ),
                    // Text(
                    //   '${context.translation.manufacture}: ${widget.workOrder!.manufacturer?.name?.cleanupWhitespace.capitalizeFirstOfEach}',
                    //   style: AppTextStyles.bodyText.copyWith(color: context.isDark ? AppColor.neutral10 : AppColor.neutral120),
                    // ),
                    16.height,
                  ],
                  ...doctorInfoSection(),
                  // ...contactInfoSection(),
                  16.height,
                  ...itemDetailsSection(),
                  16.height,
                  ...vendorDetailsSection(),
                  16.height,
                  AttachmentPicker(
                    label: context.translation.attachments,
                    attachment: attachments,
                    onlyImages: false,
                    showAsListView: true,
                    buttonIcon: 'image-plus'.toSvgAsset(color: AppColor.primary10),
                    onChange: (attachments) {
                      attachments = attachments;
                      setState(() {});
                    },
                  ),
                ],
              ).toShadowContainer(context, borderRadius: 20),
            ).expanded,
            FooterActionButton.footerContainer(
              context: context,
              child: AppFilledButton(
                buttonColor: AppColor.primary10,
                label: context.translation.submitRequest,
                onPressed: _submit,
                // buttonColor: AppColor.primary10,
              ),
            ),
          ],
        ),
      ),
    );
  }

  List<Widget> contactInfoSection() {
    return [
      context.translation.contactInfo.heading6(context).custom(color: AppColor.black10),
      8.height,
      AppTextFormField(
        labelText: "Name",
        backgroundColor: AppColor.fieldBgColor(context),
        textAlign: TextAlign.center,
        hintText: "Doc Name",
        labelStyle: AppTextStyles.textFieldLabelStyle,
        hintStyle: AppTextStyles.textFieldLabelStyle,
        textInputType: TextInputType.text,
        textInputAction: TextInputAction.next,
        showShadow: false,
        onSaved: (value) {
          _loanFormModel.docName = value;
        },
        style: Theme.of(context).textTheme.titleMedium,
      ),
      8.height,
      AppTextFormField(
        labelText: "Number",
        backgroundColor: AppColor.fieldBgColor(context),
        textAlign: TextAlign.center,
        hintText: "Doc Number",
        labelStyle: AppTextStyles.textFieldLabelStyle,
        hintStyle: AppTextStyles.textFieldLabelStyle,
        textInputType: TextInputType.phone,
        textInputAction: TextInputAction.next,
        showShadow: false,
        onSaved: (value) {
          _loanFormModel.docNumber = value;
        },
        style: Theme.of(context).textTheme.titleMedium,
      ),
      8.height,
      AppTextFormField(
        labelText: "Email",
        backgroundColor: AppColor.fieldBgColor(context),
        textAlign: TextAlign.center,
        hintText: "Doc Email",
        labelStyle: AppTextStyles.textFieldLabelStyle,
        hintStyle: AppTextStyles.textFieldLabelStyle,
        textInputType: TextInputType.emailAddress,
        textInputAction: TextInputAction.next,
        showShadow: false,
        onSaved: (value) {
          _loanFormModel.docEmail = value;
        },
        style: Theme.of(context).textTheme.titleMedium,
      ),
    ];
  }

  List<Widget> doctorInfoSection() {
    return [
      InfoHeaderWidget(context.translation.contactInfo),
      // context.translation.contactInfo.bodyText(context).custom(color: AppColor.black10),
      8.height,
      AppTextFormField(
        initialValue: "",
        labelText: "Doctor Name",
        validator: (value) {
          if ((value ?? "").isEmpty) return "Mandatory";
          return null;
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.text,
        onChange: (value) {
          _loanFormModel.docName = value;
        },
      ),
      8.height,
      AppTextFormField(
        initialValue: "",
        labelText: "Doctor Number",
        validator: (value) {
          if ((value ?? "").isEmpty) return "Mandatory";
          return null;
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.phone,
        onChange: (value) {
          _loanFormModel.docNumber = value;
        },
      ),
      8.height,
      AppTextFormField(
        initialValue: "",
        labelText: "Doctor Email",
        validator: (value) {
          if ((value ?? "").isEmpty) {
            return "Mandatory";
          } else {
            return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage;
          }
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.emailAddress,
        onChange: (value) {
          _loanFormModel.docEmail = value;
        },
      ),
    ];
  }

  List<Widget> itemDetailsSection() {
    return [
      InfoHeaderWidget('Item Details'.addTranslation),
      8.height,
      SingleItemDropDownMenu<MappedSite, MappedSiteProvider>(
        context: context,
        title: context.translation.site,
        initialValue: _loanFormModel.mappedSite,
        showShadow: false,
        enabled: !isBackUpRequest,
        validator: (value) {
          if (value == null) return "Please select a site";
          return null;
        },
        backgroundColor: AppColor.fieldBgColor(context),
        showAsBottomSheet: true,
        onSelect: (value) {
          if (value != null) {
            _loanFormModel.mappedSite = value;
            _loanFormModel.mappedDepartment = null;
            Provider.of<DepartmentLookupProvider>(context, listen: false).getData(id: _loanFormModel.mappedSite?.id);
            setState(() {});
          }
        },
      ),
      8.height,
      SingleItemDropDownMenu<TrafDepartment, DepartmentLookupProvider>(
        context: context,
        title: context.translation.department,
        matchBy: DropDownMatchType.identifier,
        showShadow: false,
        enabled: !isBackUpRequest,
        validator: (value) {
          if (value == null) return "Please select a department";
          return null;
        },
        showAsBottomSheet: true,
        initialValue: _loanFormModel.mappedDepartment,
        requestById: context.userProvider.user?.clientId,
        backgroundColor: AppColor.fieldBgColor(context),
        onSelect: (value) {
          _loanFormModel.mappedDepartment = value;
          setState(() {});
        },
      ),
      8.height,
      AppTextFormField(
        labelText: "Item Description",
        validator: (value) {
          if ((value ?? "").isEmpty) return "Mandatory";
          return null;
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.text,
        textInputAction: TextInputAction.next,
        onChange: (value) {
          _loanFormModel.itemDescription = value;
        },
      ),
      8.height,
      Row(
        children: [
          "help-circle".toSvgAsset(height: 16, width: 16),
          8.width,
          Text(
            "Specify the purpose of the loan (e.g., equipment needed for a scheduled procedure or patient case)",
            style: AppTextStyles.tinyFont2.copyWith(fontWeight: FontWeight.w400, color: context.isDark ? Colors.white : const Color(0xff3B3D4A)),
          ).expanded,
        ],
      ),
      8.height,
      AppTextFormField(
        labelText: "Request Description",
        validator: (value) {
          if ((value ?? "").isEmpty) return "Mandatory";
          return null;
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.text,
        textInputAction: TextInputAction.next,
        onChange: (value) {
          _loanFormModel.requestDescription = value;
        },
      ),
      8.height,
      AppTextFormField(
        labelText: "Model",
        validator: (value) {
          if ((value ?? "").isEmpty) return "Mandatory";
          return null;
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.text,
        textInputAction: TextInputAction.next,
        onChange: (value) {
          _loanFormModel.model = value;
        },
      ),
      8.height,
      AppTextFormField(
        labelText: "Manufacturer",
        validator: (value) {
          if ((value ?? "").isEmpty) return "Mandatory";
          return null;
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        floatingLabelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.text,
        textInputAction: TextInputAction.next,
        onChange: (value) {
          _loanFormModel.manufacturer = value;
        },
      ),
      8.height,
      SingleItemDropDownMenu<Lookup, LoanPeriodProvider>(
        context: context,
        height: 56.toScreenHeight,
        title: 'Loan Period'.addTranslation,
        showShadow: false,
        validator: (value) {
          if (value == null) return "Please select loan period";
          return null;
        },
        backgroundColor: AppColor.fieldBgColor(context),
        showAsBottomSheet: true,
        initialValue: _loanFormModel.loanProvided,
        onSelect: (status) {
          if (status != null) {
            _loanFormModel.loanProvided = status;
            setState(() {});
          }
        },
      ),
      8.height,
    ];
  }

  List<Widget> vendorDetailsSection() {
    return [
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          InfoHeaderWidget('Vendor Details'.addTranslation),
          Row(
            children: [
              Container(
                height: 24,
                width: 24,
                decoration: const BoxDecoration(
                  shape: BoxShape.circle,
                  color: AppColor.primary10, // or AppColor.blueStatus(context)
                ),
                alignment: Alignment.center,
                child: Icon(
                  !_loanFormModel.isNewVendor ? Icons.add : Icons.search,
                  color: Colors.white,
                  size: 16,
                ),
              ),
              4.width,
              Text(
                !_loanFormModel.isNewVendor ? "Add new vendor" : "Select existing vendor",
                style: AppTextStyles.bodyText.copyWith(
                  color: context.isDark ? AppColor.neutral30 : AppColor.neutral50,
                  // decoration: TextDecoration.underline,
                ),
              ),
            ],
          ).onPress(() async {
            _loanFormModel.supplier = null;
            _loanFormModel.vendorName = null;
            _loanFormModel.supEngineer = null;
            _loanFormModel.vendorRepresentativeName = null;
            setState(() {
              _loanFormModel.isNewVendor = !_loanFormModel.isNewVendor;
            });
          }),
        ],
      ),
      8.height,
      if (!_loanFormModel.isNewVendor) ...[
        SingleItemDropDownMenu<SupplierDetails, VendorProvider>(
          context: context,
          title: 'Vendor Name'.addTranslation,
          backgroundColor: AppColor.fieldBgColor(context),
          initialValue: _loanFormModel.supplier,
          showAsBottomSheet: true,
          validator: (value) {
            if (value == null) return "Please select vendor name";
            return null;
          },
          showShadow: false,
          showCancel: true,
          onSelect: (person) {
            _loanFormModel.supplier = person;
            _loanFormModel.vendorName = person?.name;
            _loanFormModel.supEngineer = null;
            _loanFormModel.vendorRepresentativeName = null;
            vendorPhoneController.text = person?.contact ?? '';
            vendorEmailController.text = person?.email ?? '';
            setState(() {});
          },
        ),
        8.height,
        SingleItemDropDownMenu<SuppPersons, NullableLoadingProvider>(
          context: context,
          backgroundColor: _loanFormModel.supplier?.suppliername == null
              ? context.isDark
                  ? AppColor.neutral20
                  : AppColor.neutral40
              : AppColor.fieldBgColor(context),
          title: "Representative Name".addTranslation,
          showShadow: false,
          validator: (value) {
            if (value == null) return "Please select representative name";
            return null;
          },
          enabled: _loanFormModel.supplier?.suppPersons?.isNotEmpty ?? false,
          staticData: _loanFormModel.supplier?.suppPersons,
          showAsBottomSheet: true,
          initialValue: _loanFormModel.supEngineer == null ? null : SuppPersons.fromJson(_loanFormModel.supEngineer?.toJson()),
          onSelect: (suppPerson) {
            if (suppPerson != null) {
              _loanFormModel.vendorRepresentativeName = suppPerson.name;
              _loanFormModel.supEngineer = SuppEngineerWorkOrders.fromJson(suppPerson.toJson());
              setState(() {});
            }
          },
        ),
      ] else ...[
        AppTextFormField(
          initialValue: "",
          labelText: "Vendor Name",
          validator: (value) {
            if ((value ?? "").isEmpty) return "Mandatory";
            return null;
          },
          style: Theme.of(context).textTheme.titleMedium,
          backgroundColor: AppColor.fieldBgColor(context),
          labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
          showShadow: false,
          textInputType: TextInputType.name,
          textInputAction: TextInputAction.next,
          onChange: (value) {
            _loanFormModel.vendorName = value;
          },
        ),
        8.height,
        AppTextFormField(
          initialValue: "",
          labelText: "Vendor Representative Name",
          validator: (value) {
            if ((value ?? "").isEmpty) return "Mandatory";
            return null;
          },
          style: Theme.of(context).textTheme.titleMedium,
          backgroundColor: AppColor.fieldBgColor(context),
          labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
          showShadow: false,
          textInputType: TextInputType.name,
          textInputAction: TextInputAction.next,
          onChange: (value) {
            _loanFormModel.vendorRepresentativeName = value;
          },
        ),
      ],
      8.height,
      AppTextFormField(
        controller: vendorPhoneController,
        labelText: "Vendor Number",
        validator: (value) {
          if ((value ?? "").isEmpty) return "Mandatory";
          return null;
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.phone,
        textInputAction: TextInputAction.next,
        onChange: (value) {
          _loanFormModel.vendorNumber = value;
        },
      ),
      8.height,
      AppTextFormField(
        controller: vendorEmailController,
        labelText: "Vendor Email",
        validator: (value) {
          if ((value ?? "").isEmpty) {
            return "Mandatory";
          } else {
            return Validator.isEmail(value!) ? null : context.translation.emailValidateMessage;
          }
        },
        style: Theme.of(context).textTheme.titleMedium,
        backgroundColor: AppColor.fieldBgColor(context),
        labelStyle: AppTextStyles.textFieldLabelStyle.copyWith(color: AppColor.textColor(context)),
        showShadow: false,
        textInputType: TextInputType.emailAddress,
        textInputAction: TextInputAction.next,
        onChange: (value) {
          _loanFormModel.vendorEmail = value;
        },
      ),
    ];
  }

  Future<void> _submit() async {
    FocusScope.of(context).unfocus();
    if (_formKey.currentState!.validate()) {
      _formKey.currentState!.save();

      _loanFormModel.loanAttachment = [];
      for (var item in attachments) {
        String fileName = CMRequestUtils.isLocalUrl(item.name ?? '') ? ("${item.name ?? ''.split("/").last}|${base64Encode(File(item.name ?? '').readAsBytesSync())}") : item.name ?? '';
        _loanFormModel.loanAttachment?.add(GenericAttachmentModel(id: 0, name: fileName, moduleReferenceId: 0));
      }
      Utils.showLoading(context);
      LoanProvider loanProvider = Provider.of<LoanProvider>(context, listen: false);
      Map<String, dynamic> body = _loanFormModel.toJson();
      body["id"] = 0;
      body["LoanTypeId"] = 0;
      body["requestorUserID"] = context.userProvider.user!.userID;

      if (isBackUpRequest) {
        body["assetId"] = widget.workOrder!.asset!.id;
        body["assetName"] = widget.workOrder!.assetNdModel!.name;
        body["assetNumber"] = widget.workOrder!.asset!.assetNumber;
        body["assetSerialNumber"] = widget.workOrder!.asset!.assetSerialNo;
        body["model"] = widget.workOrder!.model?.name;
        body["manufacturer"] = widget.workOrder!.manufacturer?.name;
        body["cMWOItemId"] = widget.workOrderId;
      }
      bool isSuccess = await loanProvider.addLoanRequest(body);
      Utils.hideLoading(context);
      if (isSuccess) {
        Navigator.pop(context);
      }
    }
  }
}
