|
|
|
|
@ -1,3 +1,4 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:mc_common_app/classes/app_state.dart';
|
|
|
|
|
@ -50,6 +51,8 @@ class ServiceVM extends BaseVM {
|
|
|
|
|
List<DropValue> citiesDropList = [];
|
|
|
|
|
double latitude = 0;
|
|
|
|
|
double longitude = 0;
|
|
|
|
|
String openTime = "";
|
|
|
|
|
String closedTime = "";
|
|
|
|
|
int role = -1;
|
|
|
|
|
int countryId = -1;
|
|
|
|
|
int cityId = -1;
|
|
|
|
|
@ -183,6 +186,8 @@ class ServiceVM extends BaseVM {
|
|
|
|
|
branchDescription = branchData.branchDescription!;
|
|
|
|
|
latitude = double.parse(branchData.latitude ?? "");
|
|
|
|
|
longitude = double.parse(branchData.longitude ?? "");
|
|
|
|
|
openTime = branchData.openTime ?? "";
|
|
|
|
|
closedTime = branchData.closeTime ?? "";
|
|
|
|
|
countryId = branchData.countryID!;
|
|
|
|
|
cityId = branchData.cityId!;
|
|
|
|
|
cityValue = DropValue(
|
|
|
|
|
@ -203,27 +208,6 @@ class ServiceVM extends BaseVM {
|
|
|
|
|
setState(ViewState.idle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<GenericRespModel> updateBranch(
|
|
|
|
|
int id,
|
|
|
|
|
String branchName,
|
|
|
|
|
String branchDescription,
|
|
|
|
|
String cityId,
|
|
|
|
|
String address,
|
|
|
|
|
String latitude,
|
|
|
|
|
String longitude, {
|
|
|
|
|
bool isNeedToDelete = true,
|
|
|
|
|
}) async {
|
|
|
|
|
return await branchRepo.updateBranch(
|
|
|
|
|
id,
|
|
|
|
|
branchName,
|
|
|
|
|
branchDescription,
|
|
|
|
|
cityId.toString(),
|
|
|
|
|
address,
|
|
|
|
|
latitude.toString(),
|
|
|
|
|
longitude.toString(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void resetValues() {
|
|
|
|
|
countryCode = "";
|
|
|
|
|
address = "";
|
|
|
|
|
@ -398,25 +382,56 @@ class ServiceVM extends BaseVM {
|
|
|
|
|
return response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onCreateBranchPressed({
|
|
|
|
|
required BuildContext context,
|
|
|
|
|
required String branchName,
|
|
|
|
|
required String branchDesc,
|
|
|
|
|
required int cityID,
|
|
|
|
|
required String address,
|
|
|
|
|
required double latitude,
|
|
|
|
|
required double longitude,
|
|
|
|
|
}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
GenericRespModel res = await branchRepo.createBranch(branchName, branchDesc, cityID.toString(), address, latitude.toString(), longitude.toString());
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (res.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.branch_created.tr());
|
|
|
|
|
updateSelectedBranchType(1);
|
|
|
|
|
pop(context);
|
|
|
|
|
getBranchAndServices();
|
|
|
|
|
Future<BranchPostingImages> convertFileToBranchPostingImages({required ImageModel imageModel}) async {
|
|
|
|
|
BranchPostingImages branchPostingImages;
|
|
|
|
|
if (imageModel.isFromNetwork ?? false) {
|
|
|
|
|
branchPostingImages = BranchPostingImages(id: imageModel.id, imageUrl: imageModel.filePath);
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(res.message ?? "");
|
|
|
|
|
File file = File(imageModel.filePath!);
|
|
|
|
|
List<int> imageBytes = await file.readAsBytes();
|
|
|
|
|
String image = base64Encode(imageBytes);
|
|
|
|
|
String fileName = file.path.split('/').last;
|
|
|
|
|
branchPostingImages = BranchPostingImages(
|
|
|
|
|
imageName: fileName,
|
|
|
|
|
imageStr: image,
|
|
|
|
|
imageUrl: file.path,
|
|
|
|
|
// id: isAdEditEnabled ? previousAdDetails!.vehiclePostingID : null, // TODO NEED TO PASS ID HERE IN CASE OF EDIT BRANCH
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return branchPostingImages;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> onCreateBranchPressed({required BuildContext context, required String branchName, required String branchDesc, required int cityID, required String address, required double latitude, required double longitude}) async {
|
|
|
|
|
try {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
|
|
|
|
|
List<BranchPostingImages> branchImages = [];
|
|
|
|
|
|
|
|
|
|
for (var image in pickedBranchImages) {
|
|
|
|
|
branchImages.add(await convertFileToBranchPostingImages(imageModel: image));
|
|
|
|
|
}
|
|
|
|
|
GenericRespModel res = await branchRepo.createBranch(
|
|
|
|
|
branchName: branchName,
|
|
|
|
|
branchDescription: branchDesc,
|
|
|
|
|
cityId: cityID,
|
|
|
|
|
address: address,
|
|
|
|
|
latitude: latitude,
|
|
|
|
|
longitude: longitude,
|
|
|
|
|
imagesList: branchImages,
|
|
|
|
|
);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (res.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.branch_created.tr());
|
|
|
|
|
updateSelectedBranchType(1);
|
|
|
|
|
pop(context);
|
|
|
|
|
getBranchAndServices();
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(res.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast(e.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -427,27 +442,40 @@ class ServiceVM extends BaseVM {
|
|
|
|
|
required String branchDesc,
|
|
|
|
|
required int cityID,
|
|
|
|
|
required String address,
|
|
|
|
|
required double latitude,
|
|
|
|
|
required String latitude,
|
|
|
|
|
required String longitude,
|
|
|
|
|
}) async {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
GenericRespModel res = await updateBranch(
|
|
|
|
|
branchID ?? 0,
|
|
|
|
|
branchName,
|
|
|
|
|
branchDescription,
|
|
|
|
|
cityId.toString(),
|
|
|
|
|
address,
|
|
|
|
|
latitude.toString(),
|
|
|
|
|
longitude.toString(),
|
|
|
|
|
);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (res.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.branch_updated.tr());
|
|
|
|
|
pop(context);
|
|
|
|
|
pop(context);
|
|
|
|
|
getBranchAndServices();
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(res.message ?? "");
|
|
|
|
|
try {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
|
|
|
|
|
List<BranchPostingImages> branchImages = [];
|
|
|
|
|
|
|
|
|
|
for (var image in pickedBranchImages) {
|
|
|
|
|
branchImages.add(await convertFileToBranchPostingImages(imageModel: image));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
GenericRespModel res = await branchRepo.updateBranch(
|
|
|
|
|
branchId: branchID,
|
|
|
|
|
branchName: branchName,
|
|
|
|
|
branchDescription: branchDesc,
|
|
|
|
|
cityId: cityID,
|
|
|
|
|
address: address,
|
|
|
|
|
latitude: latitude,
|
|
|
|
|
longitude: longitude,
|
|
|
|
|
imagesList: branchImages,
|
|
|
|
|
);
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
if (res.messageStatus == 1) {
|
|
|
|
|
Utils.showToast(LocaleKeys.branch_updated.tr());
|
|
|
|
|
pop(context);
|
|
|
|
|
pop(context);
|
|
|
|
|
getBranchAndServices();
|
|
|
|
|
} else {
|
|
|
|
|
Utils.showToast(res.message ?? "");
|
|
|
|
|
}
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.showToast(e.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|