save method

Future<void> save({
  1. bool frmImage = false,
})

Implementation

Future<void> save({bool frmImage = false}) async {
  var valid = await validMobileNumber(
      profileMobile.text.removeAllWhitespace.replaceAll("+", ""));
  // var permission = await AppPermission.getStoragePermission();
  // if (permission) {
  if (profileName.text.trim().isEmpty) {
    toToast(getTranslated("pleaseEnterUserName"));
  } else if (profileName.text.trim().length < 3) {
    toToast(getTranslated("userNameTooShort"));
  } else if (profileEmail.text.trim().isEmpty) {
    toToast(getTranslated("emailNotEmpty"));
  } else if (!emailPatternMatch.hasMatch(profileEmail.text.toString())) {
    toToast(getTranslated("pleaseEnterValidMail"));
  } else if (profileStatus.value.isEmpty) {
    toToast(getTranslated("pleaseEnterProfileStatus"));
  } else if (!valid) {
    toToast(getTranslated("pleaseEnterValidMobile"));
  } else {
    loading.value = true;
    showLoader();
    if (imagePath.value.isNotEmpty) {
      debugPrint("profile image update");
      updateProfileImage(imagePath.value, update: true);
    } else {
      if (await AppUtils.isNetConnected()) {
        debugPrint("profile update");
        var formattedNumber = await libphonenumber.parse(profileMobile.text);
        debugPrint("parse-----> $formattedNumber");
        var unformatted = formattedNumber[
            'national_number']; //profileMobile.text.replaceAll(" ", "").replaceAll("+", "");
        // var unformatted = profileMobile.text;
        Mirrorfly.updateMyProfile(
            name: profileName.text.toString(),
            email: profileEmail.text.toString(),
            mobile: unformatted,
            status: profileStatus.value.toString(),
            image: userImgUrl.value.isEmpty ? null : userImgUrl.value,
            flyCallback: (FlyResponse response) {
              loading.value = false;
              hideLoader();
              if (response.isSuccess) {
                LogMessage.d("updateMyProfile", response.data.toString());
                var data = profileUpdateFromJson(response.data);
                if (data.status != null) {
                  toToast(frmImage
                      ? getTranslated("removedProfileImage")
                      : data.message.toString());
                  if (data.status!) {
                    changed(false);
                    var userProfileData = ProData(
                        email: profileEmail.text.toString(),
                        image: userImgUrl.value,
                        mobileNumber: unformatted,
                        nickName: profileName.text,
                        name: profileName.text,
                        status: profileStatus.value);
                    SessionManagement.setCurrentUser(userProfileData);
                    if (from == Routes.login || from.isEmpty) {
                      // Mirrorfly.isTrailLicence().then((trail){
                      if (!Constants.enableContactSync) {
                        NavUtils.offNamed(Routes.dashboard,
                            arguments: const DashboardViewArguments());
                      } else {
                        NavUtils.offNamed(Routes.contactSync);
                      }
                      // });
                    }
                  }
                }
              } else {
                toToast(getTranslated("unableToUpdateProfile"));
              }
            });
        /*    .then((value) {
            LogMessage.d("updateMyProfile", value.toString());
            loading.value = false;
            hideLoader();
            if (value != null) {
              debugPrint(value);
              var data = profileUpdateFromJson(value);
              if (data.status != null) {
                toToast(frmImage ? 'Removed profile image successfully' : data.message.toString());
                if (data.status!) {
                  changed(false);
                  var userProfileData = ProData(
                      email: profileEmail.text.toString(),
                      image: userImgUrl.value,
                      mobileNumber: unformatted,
                      nickName: profileName.text,
                      name: profileName.text,
                      status: profileStatus.value);
                  SessionManagement.setCurrentUser(userProfileData);
                  if (from == Routes.login) {
                    // Mirrorfly.isTrailLicence().then((trail){
                      if(!Constants.enableContactSync) {
                        NavUtils.offNamed(Routes.dashboard);
                      }else{
                        NavUtils.offNamed(Routes.contactSync);
                      }
                    // });
                  }
                }
              }
            } else {
              toToast("Unable to update profile");
            }
          }).catchError((error) {
            loading.value = false;
            hideLoader();
            debugPrint("issue===> $error");
            toToast(error.toString());
          });*/
      } else {
        loading(false);
        hideLoader();
        toToast(getTranslated("noInternetConnection"));
      }
    }
  }
  // }
}