|
|
|
|
@ -44,7 +44,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
AdVM({required this.commonServices, required this.commonRepo, required this.adsRepo});
|
|
|
|
|
|
|
|
|
|
AdCreationSteps currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
AdCreationStepsEnum currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
|
|
|
|
|
VehicleDetailsModel? vehicleDetails;
|
|
|
|
|
|
|
|
|
|
@ -1213,64 +1213,132 @@ class AdVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
void onBackButtonPressed(BuildContext context) {
|
|
|
|
|
switch (currentProgressStep) {
|
|
|
|
|
case AdCreationSteps.vehicleDetails:
|
|
|
|
|
case AdCreationStepsEnum.vehicleDetails:
|
|
|
|
|
resetValues();
|
|
|
|
|
pop(context);
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.damageParts:
|
|
|
|
|
currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
case AdCreationStepsEnum.damageParts:
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.adDuration:
|
|
|
|
|
currentProgressStep = AdCreationSteps.damageParts;
|
|
|
|
|
case AdCreationStepsEnum.adDuration:
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.damageParts;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.reviewAd:
|
|
|
|
|
currentProgressStep = AdCreationSteps.adDuration;
|
|
|
|
|
case AdCreationStepsEnum.reviewAd:
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.adDuration;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> saveAdVehicleDetailsDraft({required bool isNew, required BuildContext context, required AdCreationStepsEnum stepNoEnum}) async {
|
|
|
|
|
AppState appState = injector.get<AppState>();
|
|
|
|
|
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
Ads ads = Ads(
|
|
|
|
|
id: !isNew ? previousAdDetails!.id : 0,
|
|
|
|
|
adsDurationID: vehicleAdDurationId.selectedId == -1 ? 0 : vehicleAdDurationId.selectedId,
|
|
|
|
|
countryId: vehicleCountryId.selectedId,
|
|
|
|
|
);
|
|
|
|
|
List<VehiclePostingImages> vehicleImages = [];
|
|
|
|
|
|
|
|
|
|
for (var image in pickedPostingImages) {
|
|
|
|
|
vehicleImages.add(await convertFileToVehiclePostingImages(imageModel: image));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VehiclePosting vehiclePosting = VehiclePosting(
|
|
|
|
|
id: !isNew ? previousAdDetails!.vehiclePostingID : null,
|
|
|
|
|
userID: appState.getUser.data!.userInfo!.userId,
|
|
|
|
|
vehicleType: vehicleTypeId.selectedId,
|
|
|
|
|
vehicleModelID: vehicleModelId.selectedId,
|
|
|
|
|
vehicleModelYearID: vehicleModelYearId.selectedId,
|
|
|
|
|
vehicleColorID: vehicleColorId.selectedId,
|
|
|
|
|
vehicleCategoryID: vehicleCategoryId.selectedId,
|
|
|
|
|
vehicleConditionID: vehicleConditionId.selectedId,
|
|
|
|
|
vehicleMileageID: vehicleMileageId.selectedId,
|
|
|
|
|
vehicleTransmissionID: vehicleTransmissionId.selectedId,
|
|
|
|
|
vehicleSellerTypeID: vehicleSellerTypeId.selectedId == -1 ? 1 : vehicleSellerTypeId.selectedId,
|
|
|
|
|
cityID: vehicleCityId.selectedId,
|
|
|
|
|
price: int.parse(vehicleDemandAmount),
|
|
|
|
|
vehicleVIN: vehicleVin,
|
|
|
|
|
vehicleDescription: vehicleDescription,
|
|
|
|
|
vehicleTitle: vehicleTitle,
|
|
|
|
|
vehicleDescriptionN: vehicleDescription,
|
|
|
|
|
isFinanceAvailable: financeAvailableStatus,
|
|
|
|
|
warantyYears: int.parse(warrantyDuration),
|
|
|
|
|
demandAmount: int.parse(vehicleDemandAmount),
|
|
|
|
|
vehiclePostingImages: vehicleImages,
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
AdsCreationPayloadModel adsCreationPayloadModel = AdsCreationPayloadModel(ads: ads, vehiclePosting: vehiclePosting);
|
|
|
|
|
|
|
|
|
|
GenericRespModel respModel = await adsRepo.createOrUpdateDraftAd(
|
|
|
|
|
adsCreationPayloadModel: adsCreationPayloadModel,
|
|
|
|
|
isCreateNew: isNew,
|
|
|
|
|
stepNo: stepNoEnum,
|
|
|
|
|
);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
return Future.value(respModel.messageStatus == 1 ? respModel.data : -1);
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
logger.e(e.toString());
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future saveAdDamagePartDetailsDraft() async {}
|
|
|
|
|
|
|
|
|
|
Future saveAdDurationsDraft() async {}
|
|
|
|
|
|
|
|
|
|
void updateCurrentStep(BuildContext context) async {
|
|
|
|
|
switch (currentProgressStep) {
|
|
|
|
|
case AdCreationSteps.vehicleDetails:
|
|
|
|
|
case AdCreationStepsEnum.vehicleDetails:
|
|
|
|
|
if (isVehicleDetailsValidated()) {
|
|
|
|
|
currentProgressStep = AdCreationSteps.damageParts;
|
|
|
|
|
int adID = await saveAdVehicleDetailsDraft(isNew: previousAdDetails == null || previousAdDetails!.id == null, context: context, stepNoEnum: AdCreationStepsEnum.vehicleDetails);
|
|
|
|
|
if (previousAdDetails == null || previousAdDetails!.id == null) {
|
|
|
|
|
previousAdDetails = AdDetailsModel();
|
|
|
|
|
previousAdDetails!.id = adID;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.damageParts;
|
|
|
|
|
getVehicleDamagePartsList();
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.damageParts:
|
|
|
|
|
case AdCreationStepsEnum.damageParts:
|
|
|
|
|
if (isDamagePartsValidated()) {
|
|
|
|
|
currentProgressStep = AdCreationSteps.adDuration;
|
|
|
|
|
await saveAdVehicleDetailsDraft(isNew: false, context: context, stepNoEnum: AdCreationStepsEnum.damageParts);
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.adDuration;
|
|
|
|
|
if (vehicleAdsDurations.isEmpty) {
|
|
|
|
|
getVehicleAdsDuration();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
getVehicleAdsSpecialServices(countryId: vehicleCountryId.selectedId, cityId: vehicleCityId.selectedId, specialServiceType: 1);
|
|
|
|
|
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.adDuration:
|
|
|
|
|
case AdCreationStepsEnum.adDuration:
|
|
|
|
|
// log("state: ${AppState().getUser.data!.accessToken}");
|
|
|
|
|
if (isAdDurationValidated()) {
|
|
|
|
|
currentProgressStep = AdCreationSteps.reviewAd;
|
|
|
|
|
await saveAdVehicleDetailsDraft(isNew: false, context: context, stepNoEnum: AdCreationStepsEnum.adDuration);
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.reviewAd;
|
|
|
|
|
notifyListeners();
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case AdCreationSteps.reviewAd:
|
|
|
|
|
case AdCreationStepsEnum.reviewAd:
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
try {
|
|
|
|
|
int status = await createNewAd();
|
|
|
|
|
if (status != 1) {
|
|
|
|
|
bool status = await createNewAd();
|
|
|
|
|
if (!status) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
isAdEditEnabled = false;
|
|
|
|
|
isExtendAdEditEnabled = false;
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
resetValues();
|
|
|
|
|
updateIsExploreAds(false);
|
|
|
|
|
applyFilterOnMyAds(adPostStatusEnum: AdPostStatus.pendingForReview); //pending for review
|
|
|
|
|
@ -1444,7 +1512,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
vehicleDamageCards.clear();
|
|
|
|
|
specialServiceCards.clear();
|
|
|
|
|
vehicleAdsSpecialServices.clear();
|
|
|
|
|
currentProgressStep = AdCreationSteps.vehicleDetails;
|
|
|
|
|
currentProgressStep = AdCreationStepsEnum.vehicleDetails;
|
|
|
|
|
vehicleTypeId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
vehicleModelId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
// vehicleAdDurationId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: "");
|
|
|
|
|
@ -1604,7 +1672,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<int> createNewAd() async {
|
|
|
|
|
Future<bool> createNewAd() async {
|
|
|
|
|
AppState appState = injector.get<AppState>();
|
|
|
|
|
List<int> adsSelectedServices = [];
|
|
|
|
|
|
|
|
|
|
@ -1687,7 +1755,7 @@ class AdVM extends BaseVM {
|
|
|
|
|
|
|
|
|
|
Utils.showToast(respModel.message.toString());
|
|
|
|
|
|
|
|
|
|
return Future.value(respModel.messageStatus);
|
|
|
|
|
return Future.value(respModel.messageStatus == 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<VehiclePostingImages> convertFileToVehiclePostingImages({required ImageModel imageModel}) async {
|
|
|
|
|
|