initProfile method

void initProfile()

Implementation

void initProfile() async {
  // isEditing.value = false;
  try {
    await authenticationController.getUserProfile();
    final profile = authenticationController.userProfileModel.value.data;
    if (profile != null &&
        profile.user != null &&
        profile.user!.phone != null) {
      if (profile.user!.phone!.startsWith('+')) {
        phoneNumberData.value = await parsePhoneNumber(profile.user!.phone!);
      }
    }
    firstNameController.text = (profile?.user?.firstName ?? "").trim();
    middleNameController.text = (profile?.user?.middleName ?? "").trim();
    lastNameController.text = (profile?.user?.lastName ?? "").trim();
    phoneNumberController.text = phoneNumberData['number'] == null
        ? profile?.user?.phone ?? ""
        : phoneNumberData['number'].toString().contains('+')
            ? phoneNumberData['number'].toString().replaceAll('+', '')
            : phoneNumberData['number'].toString();
    emailController.text = profile?.user?.email ?? "";
    countryCode.value = phoneNumberData['countryCode'] == null
        ? profile?.user?.countryCode ?? ""
        : '+${phoneNumberData['countryCode']}';
    ////
    residentCountry.value =
        getCountryName(profile?.user?.residentCountry ?? '') ?? '';
    addressLine1Controlller.text = profile?.user?.addressLine1 ?? '';
    addressLine2Controlller.text = profile?.user?.addressLine2 ?? '';
    cityController.text = profile?.user?.city ?? '';
    country.value = getCountryName(profile?.user?.country ?? '') ?? '';
    // print(
    //     "KKK->${profile?.passportInformation?.dob ?? ''} -||- ${profile?.passportInformation?.gender ?? ''}");
    // passportIssuingCountry.value = getCountryName(
    //         profile?.passportInformation?.passportIssuingCountry ?? '') ??
    //     '';
    // passportController.text = profile?.passportInformation?.passportNo ?? '';
    // dobController.text =
    //     profile?.passportInformation?.dob?.split('T')[0] ?? '';
    // passportExpiryController.text =
    //     profile?.passportInformation?.passportExpiry?.split('T')[0] ?? '';
    // nationality.value = profile?.passportInformation?.nationality ?? '';
    // selectedGender.value =
    //     (profile?.passportInformation?.gender?[0].toUpperCase() ?? '') +
    //         (profile?.passportInformation?.gender?.substring(1) ?? '');
    phoneFieldKey.value = phoneFieldKey.value + 1;
    phoneFieldKey.refresh();
  } catch (e) {
    log('Error loading profile: ${e.toString()}');
  }
}