save method

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

Implementation

Future<void> save({bool frmImage = false, required BuildContext context}) async {
  // if (await askStoragePermission(context)) {
    if (await validation()){
      loading.value = true;
      if(context.mounted)showLoader(context);
      if (imagePath.value.isNotEmpty) {
        debugPrint("profile image update");
        if(context.mounted)updateProfileImage(path: imagePath.value, update: true, context: context);
      } else {
        if (await AppUtils.isNetConnected()) {
          debugPrint("profile update");
          var formattedNumber = await lib_phone_number.parse(profileMobile.text);
          debugPrint("parse-----> $formattedNumber");
          var unformatted = formattedNumber['national_number'];//profileMobile.text.replaceAll(" ", Constants.emptyString).replaceAll("+", Constants.emptyString);
          // var unformatted = profileMobile.text;
          debugPrint('unformatted : $unformatted');
          Mirrorfly
              .updateMyProfile(
              profileName.text.toString(),
              profileEmail.text.toString(),
              unformatted,
              profileStatus.value.toString(),
              userImgUrl.value.isEmpty ? null : userImgUrl.value
          )
              .then((value) {
            mirrorFlyLog("updateMyProfile", value);
            loading.value = false;
            hideLoader(context);
            if (value != null) {
              debugPrint(value);
              var data = profileUpdateFromJson(value);
              if (data.status != null) {
                toToast(frmImage ? AppConstants.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);
                }
              }
            } else {
              toToast(AppConstants.unableToUpdateProfile);
            }
          }).catchError((error) {
            loading.value = false;
            hideLoader(context);
            debugPrint("issue===> $error");
            toToast(error.toString());
          });
        } else {
          loading(false);
          if(context.mounted)hideLoader(context);
          toToast(AppConstants.noInternetConnection);
        }
      }
    }
  // }
}