user profile 7 api's & fixes
parent
79d1f37b12
commit
3b35288c9d
@ -1,611 +0,0 @@
|
|||||||
// import 'dart:convert';
|
|
||||||
// import 'dart:io';
|
|
||||||
//
|
|
||||||
// import 'package:car_provider_app/repositories/branch_repo.dart';
|
|
||||||
// import 'package:mc_common_app/models/m_response.dart';
|
|
||||||
//
|
|
||||||
// import 'package:mc_common_app/models/model/provider_model.dart';
|
|
||||||
// import 'package:mc_common_app/models/profile/categroy.dart';
|
|
||||||
// import 'package:mc_common_app/models/profile/document.dart';
|
|
||||||
// import 'package:mc_common_app/models/profile/services.dart';
|
|
||||||
// import 'package:mc_common_app/models/services/branch_model.dart';
|
|
||||||
// import 'package:mc_common_app/models/services/item_model.dart';
|
|
||||||
// import 'package:mc_common_app/models/services/service_model.dart';
|
|
||||||
// import 'package:mc_common_app/models/user/cities.dart';
|
|
||||||
// import 'package:mc_common_app/models/user/country.dart';
|
|
||||||
// import 'package:mc_common_app/repositories/common_repo.dart';
|
|
||||||
// import 'package:mc_common_app/services/common_services.dart';
|
|
||||||
// import 'package:mc_common_app/utils/enums.dart';
|
|
||||||
// import 'package:mc_common_app/utils/utils.dart';
|
|
||||||
// import 'package:mc_common_app/view_models/base_view_model.dart';
|
|
||||||
// import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
||||||
// import 'package:file_picker/file_picker.dart';
|
|
||||||
//
|
|
||||||
// class ServiceVM extends BaseVM {
|
|
||||||
// final BranchRepo branchRepo;
|
|
||||||
// final CommonAppServices commonServices;
|
|
||||||
// final CommonRepo commonRepo;
|
|
||||||
//
|
|
||||||
// ServiceVM({required this.branchRepo, required this.commonServices, required this.commonRepo});
|
|
||||||
//
|
|
||||||
// //Documents & Branches
|
|
||||||
// int selectedBranchStatus = 3;
|
|
||||||
// Document? document;
|
|
||||||
// ProviderModel? branchs;
|
|
||||||
// Country? country;
|
|
||||||
// Cities? cities;
|
|
||||||
// DropValue? countryValue;
|
|
||||||
// DropValue? cityValue;
|
|
||||||
// List<DropValue> countryDropList = [];
|
|
||||||
// List<DropValue> citiesDropList = [];
|
|
||||||
// double latitude = 0, longitude = 0;
|
|
||||||
// int role = -1, countryId = -1, cityId = -1;
|
|
||||||
// String countryCode = "", address = "", branchName = "", branchDescription = "";
|
|
||||||
//
|
|
||||||
// getServiceProviderDocument(int providerId) async {
|
|
||||||
// setState(ViewState.busy);
|
|
||||||
// document = await branchRepo.getServiceProviderDocument(providerId);
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// selectFile(int index) async {
|
|
||||||
// File? file = await commonServices.pickFile(fileType: FileType.custom, allowedExtensions: ['png', 'pdf', 'jpeg']);
|
|
||||||
//
|
|
||||||
// if (file != null) {
|
|
||||||
// int sizeInBytes = file.lengthSync();
|
|
||||||
// // double sizeInMb = sizeInBytes / (1024 * 1024);
|
|
||||||
// if (sizeInBytes > 1000) {
|
|
||||||
// Utils.showToast("File is larger then 1KB");
|
|
||||||
// } else {
|
|
||||||
// document!.data![index].document = Utils.convertFileToBase64(file);
|
|
||||||
// document!.data![index].fileExt = Utils.checkFileExt(file.path);
|
|
||||||
// document!.data![index].documentUrl = file.path;
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// // User canceled the picker
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Future<MResponse> updateDocument(List<DocumentData>? data) async {
|
|
||||||
// return await branchRepo.serviceProviderDocumentsUpdate(data);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //Create new branch
|
|
||||||
// getBranchAndServices() async {
|
|
||||||
// setState(ViewState.busy);
|
|
||||||
// branchs = await branchRepo.getBranchAndServices();
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// getAllCountriesList(BranchModel? branchData, String countryCode) async {
|
|
||||||
// setState(ViewState.busy);
|
|
||||||
// resetValues();
|
|
||||||
// country = await commonRepo.getAllCountries();
|
|
||||||
// country!.data?.forEach((element) {
|
|
||||||
// if (branchData != null) if (branchData.id != null) {
|
|
||||||
// if (element.id == branchData.countryID) {
|
|
||||||
// countryValue = DropValue(element.id ?? 0, countryCode == "SA" ? (element.countryNameN ?? "") : (element.countryName ?? ""), element.countryCode ?? "");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// countryDropList.add(DropValue(element.id ?? 0, countryCode == "SA" ? (element.countryNameN ?? "") : (element.countryName ?? ""), element.countryCode ?? ""));
|
|
||||||
// });
|
|
||||||
// if (branchData != null) if (branchData.id != null) getAllCities(branchData, countryCode);
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// getAllCities(BranchModel? branchData, String countryCode) async {
|
|
||||||
// setState(ViewState.busy);
|
|
||||||
// citiesDropList.clear();
|
|
||||||
// cities = null;
|
|
||||||
// cityId = -1;
|
|
||||||
// cities = await commonRepo.getAllCites(countryId.toString());
|
|
||||||
// cities!.data?.forEach((element) {
|
|
||||||
// if (branchData != null && branchData.id != null) {
|
|
||||||
// if (element.id == branchData.cityId) {
|
|
||||||
// address = branchData.address!;
|
|
||||||
// branchName = branchData.branchName!;
|
|
||||||
// branchDescription = branchData.branchDescription!;
|
|
||||||
// latitude = double.parse(branchData.latitude ?? "");
|
|
||||||
// longitude = double.parse(branchData.longitude ?? "");
|
|
||||||
// countryId = branchData.countryID!;
|
|
||||||
// cityId = branchData.cityId!;
|
|
||||||
// cityValue = DropValue(element.id ?? 0, countryCode == "SA" ? (element.cityNameN ?? "") : (element.cityName ?? ""), element.id.toString() ?? "");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// citiesDropList.add(DropValue(element.id ?? 0, countryCode == "SA" ? (element.cityNameN ?? "") : (element.cityName ?? ""), element.id.toString() ?? ""));
|
|
||||||
// });
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Future<MResponse> createBranch(String branchName, String branchDescription, String cityId, String address, String latitude, String longitude) async {
|
|
||||||
// return await branchRepo.createBranch(branchName, branchDescription, cityId.toString(), address, latitude.toString(), longitude.toString());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Future<MResponse> updateBranch(int id, String branchName, String branchDescription, String cityId, String address, String latitude, String longitude, {bool isNeedToDelete = true}) async {
|
|
||||||
// return await branchRepo.updateBranch(id ?? 0, branchName, branchDescription, cityId.toString(), address, latitude.toString(), longitude.toString());
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// resetValues() {
|
|
||||||
// countryCode = "";
|
|
||||||
// address = "";
|
|
||||||
// branchName = "";
|
|
||||||
// branchDescription = "";
|
|
||||||
// latitude = 0;
|
|
||||||
// longitude = 0;
|
|
||||||
// role = -1;
|
|
||||||
// countryId = -1;
|
|
||||||
// cityId = -1;
|
|
||||||
// countryDropList.clear();
|
|
||||||
// countryId = -1;
|
|
||||||
// cityId = -1;
|
|
||||||
// cities = null;
|
|
||||||
// categoryDropList = [];
|
|
||||||
// servicesDropList = [];
|
|
||||||
// services = null;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// //Create Services
|
|
||||||
// Services? services;
|
|
||||||
// List<DropValue> categoryDropList = [];
|
|
||||||
// List<DropValue> servicesDropList = [];
|
|
||||||
//
|
|
||||||
// fetchBranchCategory(String countryCode) async {
|
|
||||||
// categoryDropList.clear();
|
|
||||||
// servicesDropList = [];
|
|
||||||
// services = null;
|
|
||||||
// setState(ViewState.busy);
|
|
||||||
// Category? category = await branchRepo.fetchBranchCategory();
|
|
||||||
// category.data?.forEach((element) {
|
|
||||||
// categoryDropList.add(DropValue(
|
|
||||||
// element.id ?? 0,
|
|
||||||
// ((element.categoryName!.isEmpty
|
|
||||||
// ? "N/A"
|
|
||||||
// : countryCode == "SA"
|
|
||||||
// ? element.categoryNameN
|
|
||||||
// : element.categoryName) ??
|
|
||||||
// "N/A"),
|
|
||||||
// ""));
|
|
||||||
// });
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// fetchServicesByCategoryId(String categoryId) async {
|
|
||||||
// servicesDropList = [];
|
|
||||||
// setState(ViewState.busy);
|
|
||||||
// services = await branchRepo.fetchServicesByCategoryId(categoryId);
|
|
||||||
//
|
|
||||||
// for (var element in services!.data!) {
|
|
||||||
// servicesDropList.add(DropValue(element.id ?? 0, element.description ?? "N/aA", ""));
|
|
||||||
// }
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Future<MResponse> createService(List<Map<String, dynamic>> map) async {
|
|
||||||
// return await branchRepo.createService(map);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Future<MResponse> updateServices(List<Map<String, dynamic>> map) async {
|
|
||||||
// return await branchRepo.updateService(map);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// updateSelectedBranchType(int status) {
|
|
||||||
// selectedBranchStatus = status;
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// List<ServiceModel>? matchedServices;
|
|
||||||
// bool isAllSelected = false;
|
|
||||||
//
|
|
||||||
// getAllMatchedServices(int oldBranchId, int newBranchId, int categoryId) async {
|
|
||||||
// matchedServices = null;
|
|
||||||
// MResponse response = await branchRepo.getMatchedServices(oldBranchId, newBranchId, categoryId);
|
|
||||||
// matchedServices = [];
|
|
||||||
// if (response.messageStatus == 1) {
|
|
||||||
// matchedServices = List<ServiceModel>.from(response.data.map((x) => ServiceModel.fromJson(x)));
|
|
||||||
// }
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// selectAllServices(bool value) {
|
|
||||||
// for (var element in matchedServices!) {
|
|
||||||
// element.isExpandedOrSelected = value;
|
|
||||||
// for (var item in element.serviceItems!) {
|
|
||||||
// item.isUpdateOrSelected = value;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// isAllSelected = value;
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// updateServiceItem(int serviceIndex, bool value) {
|
|
||||||
// for (var element in matchedServices![serviceIndex].serviceItems!) {
|
|
||||||
// element.isUpdateOrSelected = value;
|
|
||||||
// }
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// copyItems(int index, List<ItemData> copiedItems) {
|
|
||||||
// matchedServices![index].serviceItems = copiedItems;
|
|
||||||
// notifyListeners();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// Future<MResponse> duplicateItems(Map<String, dynamic> map) async {
|
|
||||||
// return await branchRepo.duplicateItems(map);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
import 'dart:io';
|
|
||||||
import 'package:mc_common_app/repositories/branch_repo.dart';
|
|
||||||
import 'package:file_picker/file_picker.dart';
|
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:mc_common_app/models/general_models/m_response.dart';
|
|
||||||
import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart';
|
|
||||||
import 'package:mc_common_app/models/provider_branches_models/profile/categroy.dart';
|
|
||||||
import 'package:mc_common_app/models/provider_branches_models/profile/document.dart';
|
|
||||||
import 'package:mc_common_app/models/provider_branches_models/profile/services.dart';
|
|
||||||
import 'package:mc_common_app/models/provider_branches_models/provider_model.dart';
|
|
||||||
import 'package:mc_common_app/models/services_models/item_model.dart';
|
|
||||||
import 'package:mc_common_app/models/services_models/service_model.dart';
|
|
||||||
import 'package:mc_common_app/models/user_models/branch_user.dart';
|
|
||||||
import 'package:mc_common_app/models/user_models/cities.dart';
|
|
||||||
import 'package:mc_common_app/models/user_models/country.dart';
|
|
||||||
import 'package:mc_common_app/repositories/common_repo.dart';
|
|
||||||
import 'package:mc_common_app/services/common_services.dart';
|
|
||||||
import 'package:mc_common_app/utils/enums.dart';
|
|
||||||
import 'package:mc_common_app/utils/utils.dart';
|
|
||||||
import 'package:mc_common_app/view_models/base_view_model.dart';
|
|
||||||
import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart';
|
|
||||||
|
|
||||||
class ServiceVM extends BaseVM {
|
|
||||||
final BranchRepo branchRepo;
|
|
||||||
final CommonAppServices commonServices;
|
|
||||||
final CommonRepo commonRepo;
|
|
||||||
|
|
||||||
ServiceVM({
|
|
||||||
required this.branchRepo,
|
|
||||||
required this.commonServices,
|
|
||||||
required this.commonRepo,
|
|
||||||
});
|
|
||||||
|
|
||||||
// Documents & Branches
|
|
||||||
int selectedBranchStatus = 3;
|
|
||||||
Document? document;
|
|
||||||
ProviderModel? branches;
|
|
||||||
Country? country;
|
|
||||||
Cities? cities;
|
|
||||||
DropValue? countryValue;
|
|
||||||
DropValue? cityValue;
|
|
||||||
List<DropValue> countryDropList = [];
|
|
||||||
List<DropValue> citiesDropList = [];
|
|
||||||
double latitude = 0;
|
|
||||||
double longitude = 0;
|
|
||||||
int role = -1;
|
|
||||||
int countryId = -1;
|
|
||||||
int cityId = -1;
|
|
||||||
String countryCode = "";
|
|
||||||
String address = "";
|
|
||||||
String branchName = "";
|
|
||||||
String branchDescription = "";
|
|
||||||
|
|
||||||
Future<void> getServiceProviderDocument(int providerId) async {
|
|
||||||
setState(ViewState.busy);
|
|
||||||
document = await branchRepo.getServiceProviderDocument(providerId);
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> selectFile(BuildContext context, int index) async {
|
|
||||||
final File? file = await commonServices.pickFile(
|
|
||||||
context,
|
|
||||||
fileType: FileType.custom,
|
|
||||||
allowedExtensions: ['png', 'pdf', 'jpeg'],
|
|
||||||
);
|
|
||||||
|
|
||||||
// if (result != null) {
|
|
||||||
// final File file = File(result.files.single.path!);
|
|
||||||
// final int sizeInBytes = file.lengthSync();
|
|
||||||
//
|
|
||||||
// if (sizeInBytes > 1000) {
|
|
||||||
// Utils.showToast("File is larger than 1KB");
|
|
||||||
// } else {
|
|
||||||
// document!.data![index].document = Utils.convertFileToBase64(file);
|
|
||||||
// document!.data![index].fileExt = Utils.checkFileExt(file.path);
|
|
||||||
// document!.data![index].documentUrl = file.path;
|
|
||||||
// setState(ViewState.idle);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// // User canceled the picker
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (file != null) {
|
|
||||||
int sizeInBytes = file.lengthSync();
|
|
||||||
// double sizeInMb = sizeInBytes / (1024 * 1024);
|
|
||||||
if (sizeInBytes > 1000000) {
|
|
||||||
Utils.showToast("File is larger then 1KB");
|
|
||||||
} else {
|
|
||||||
document!.data![index].document = Utils.convertFileToBase64(file);
|
|
||||||
document!.data![index].fileExt = Utils.checkFileExt(file.path);
|
|
||||||
document!.data![index].documentUrl = file.path;
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// User canceled the picker
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> updateDocument(List<DocumentData>? data) async {
|
|
||||||
return await branchRepo.serviceProviderDocumentsUpdate(data);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create new branch
|
|
||||||
Future<void> getBranchAndServices() async {
|
|
||||||
setState(ViewState.busy);
|
|
||||||
branches = await branchRepo.getBranchAndServices();
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> getAllCountriesList(BranchDetailModel? branchData, String countryCode) async {
|
|
||||||
cities = null;
|
|
||||||
country = null;
|
|
||||||
setState(ViewState.busy);
|
|
||||||
resetValues();
|
|
||||||
country = await commonRepo.getAllCountries();
|
|
||||||
country!.data?.forEach((element) {
|
|
||||||
if (branchData != null && branchData.id != null) {
|
|
||||||
if (element.id == branchData.countryID) {
|
|
||||||
countryId = element.id ?? -1;
|
|
||||||
countryValue = DropValue(
|
|
||||||
element.id ?? 0,
|
|
||||||
countryCode == "SA" ? (element.countryNameN ?? "") : (element.countryName ?? ""),
|
|
||||||
element.countryCode ?? "",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
countryDropList.add(
|
|
||||||
DropValue(
|
|
||||||
element.id ?? 0,
|
|
||||||
countryCode == "SA" ? (element.countryNameN ?? "") : (element.countryName ?? ""),
|
|
||||||
element.countryCode ?? "",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
if (branchData != null && branchData.id != null) {
|
|
||||||
await getAllCities(branchData, countryCode);
|
|
||||||
}
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> getAllCities(BranchDetailModel? branchData, String countryCode) async {
|
|
||||||
setState(ViewState.busy);
|
|
||||||
citiesDropList = [];
|
|
||||||
cities = null;
|
|
||||||
cityId = -1;
|
|
||||||
cityValue = null;
|
|
||||||
cities = await commonRepo.getAllCites(countryId.toString());
|
|
||||||
cities!.data?.forEach((element) {
|
|
||||||
if (branchData != null && branchData.id != null) {
|
|
||||||
if (element.id == branchData.cityId) {
|
|
||||||
address = branchData.address!;
|
|
||||||
branchName = branchData.branchName!;
|
|
||||||
branchDescription = branchData.branchDescription!;
|
|
||||||
latitude = double.parse(branchData.latitude ?? "");
|
|
||||||
longitude = double.parse(branchData.longitude ?? "");
|
|
||||||
countryId = branchData.countryID!;
|
|
||||||
cityId = branchData.cityId!;
|
|
||||||
cityValue = DropValue(
|
|
||||||
element.id ?? 0,
|
|
||||||
countryCode == "SA" ? (element.cityNameN ?? "") : (element.cityName ?? ""),
|
|
||||||
element.id.toString() ?? "",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
citiesDropList.add(
|
|
||||||
DropValue(
|
|
||||||
element.id ?? 0,
|
|
||||||
countryCode == "SA" ? (element.cityNameN ?? "") : (element.cityName ?? ""),
|
|
||||||
element.id.toString() ?? "",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> createBranch(String branchName, String branchDescription, String cityId, String address, String latitude, String longitude) async {
|
|
||||||
return await branchRepo.createBranch(branchName, branchDescription, cityId.toString(), address, latitude.toString(), longitude.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> updateBranch(
|
|
||||||
int id,
|
|
||||||
String branchName,
|
|
||||||
String branchDescription,
|
|
||||||
String cityId,
|
|
||||||
String address,
|
|
||||||
String latitude,
|
|
||||||
String longitude, {
|
|
||||||
bool isNeedToDelete = true,
|
|
||||||
}) async {
|
|
||||||
return await branchRepo.updateBranch(
|
|
||||||
id ?? 0,
|
|
||||||
branchName,
|
|
||||||
branchDescription,
|
|
||||||
cityId.toString(),
|
|
||||||
address,
|
|
||||||
latitude.toString(),
|
|
||||||
longitude.toString(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
void resetValues() {
|
|
||||||
countryCode = "";
|
|
||||||
address = "";
|
|
||||||
branchName = "";
|
|
||||||
branchDescription = "";
|
|
||||||
latitude = 0;
|
|
||||||
longitude = 0;
|
|
||||||
role = -1;
|
|
||||||
countryId = -1;
|
|
||||||
cityId = -1;
|
|
||||||
countryDropList.clear();
|
|
||||||
countryId = -1;
|
|
||||||
cityId = -1;
|
|
||||||
cities = null;
|
|
||||||
categoryDropList = [];
|
|
||||||
servicesDropList = [];
|
|
||||||
services = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create Services
|
|
||||||
Services? services;
|
|
||||||
List<DropValue> categoryDropList = [];
|
|
||||||
List<DropValue> servicesDropList = [];
|
|
||||||
|
|
||||||
Future<void> fetchBranchCategory(String countryCode) async {
|
|
||||||
categoryDropList.clear();
|
|
||||||
servicesDropList = [];
|
|
||||||
services = null;
|
|
||||||
setOnlyState(ViewState.busy);
|
|
||||||
Category? category = await branchRepo.fetchBranchCategory();
|
|
||||||
category.data?.forEach((element) {
|
|
||||||
categoryDropList.add(
|
|
||||||
DropValue(
|
|
||||||
element.id ?? 0,
|
|
||||||
((element.categoryName!.isEmpty
|
|
||||||
? "N/A"
|
|
||||||
: countryCode == "SA"
|
|
||||||
? element.categoryNameN
|
|
||||||
: element.categoryName) ??
|
|
||||||
"N/A"),
|
|
||||||
"",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> fetchServicesByCategoryId(int categoryId) async {
|
|
||||||
servicesDropList = [];
|
|
||||||
setState(ViewState.busy);
|
|
||||||
services = await branchRepo.fetchServicesByCategoryId(serviceCategoryId: categoryId); // to get all the services
|
|
||||||
for (var element in services!.data!) {
|
|
||||||
servicesDropList.add(
|
|
||||||
DropValue(
|
|
||||||
element.id ?? 0,
|
|
||||||
element.description ?? "N/A",
|
|
||||||
"",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> fetchProviderServices(String branchID, String categoryId) async {
|
|
||||||
servicesDropList = [];
|
|
||||||
services = null;
|
|
||||||
setState(ViewState.busy);
|
|
||||||
services = await branchRepo.fetchProviderServices(branchID, categoryId);
|
|
||||||
|
|
||||||
for (var element in services!.data!) {
|
|
||||||
servicesDropList.add(
|
|
||||||
DropValue(
|
|
||||||
element.id ?? 0,
|
|
||||||
element.description ?? "N/A",
|
|
||||||
"",
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> createService(List<Map<String, dynamic>> map) async {
|
|
||||||
return await branchRepo.createService(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> updateServices(List<Map<String, dynamic>> map) async {
|
|
||||||
return await branchRepo.updateService(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateSelectedBranchType(int status) {
|
|
||||||
selectedBranchStatus = status;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
List<ServiceModel>? matchedServices;
|
|
||||||
bool isAllSelected = false;
|
|
||||||
|
|
||||||
Future<void> getAllMatchedServices(int oldBranchId, int newBranchId, int categoryId) async {
|
|
||||||
matchedServices = null;
|
|
||||||
final MResponse response = await branchRepo.getMatchedServices(oldBranchId, newBranchId, categoryId);
|
|
||||||
matchedServices = [];
|
|
||||||
|
|
||||||
if (response.messageStatus == 1) {
|
|
||||||
matchedServices = List<ServiceModel>.from(response.data.map((x) => ServiceModel.fromJson(x)));
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void selectAllServices(bool value) {
|
|
||||||
for (var element in matchedServices!) {
|
|
||||||
element.isExpandedOrSelected = value;
|
|
||||||
for (var item in element.serviceItems!) {
|
|
||||||
item.isUpdateOrSelected = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
isAllSelected = value;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void updateServiceItem(int serviceIndex, bool value) {
|
|
||||||
for (var element in matchedServices![serviceIndex].serviceItems!) {
|
|
||||||
element.isUpdateOrSelected = value;
|
|
||||||
}
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
void copyItems(int index, List<ItemData> copiedItems) {
|
|
||||||
matchedServices![index].serviceItems = copiedItems;
|
|
||||||
notifyListeners();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> duplicateItems(Map<String, dynamic> map) async {
|
|
||||||
return await branchRepo.duplicateItems(map);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Branch Users
|
|
||||||
List<BranchUser> allProviderDealersList = [];
|
|
||||||
List<BranchUser> branchUserList = [];
|
|
||||||
|
|
||||||
getAllProviderDealers(Map<String, dynamic> map) async {
|
|
||||||
setState(ViewState.busy);
|
|
||||||
MResponse response = await branchRepo.getAllProviderDealers(map);
|
|
||||||
if (response.messageStatus == 1) {
|
|
||||||
allProviderDealersList = [];
|
|
||||||
allProviderDealersList = List<BranchUser>.from(response.data.map((x) => BranchUser.fromJson(x)));
|
|
||||||
}
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<void> getBranchUsers(Map<String, dynamic> map) async {
|
|
||||||
setState(ViewState.busy);
|
|
||||||
MResponse response = await branchRepo.getBranchUsers(map);
|
|
||||||
if (response.messageStatus == 1) {
|
|
||||||
branchUserList = [];
|
|
||||||
branchUserList = List<BranchUser>.from(response.data.map((x) => BranchUser.fromJson(x)));
|
|
||||||
}
|
|
||||||
setState(ViewState.idle);
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> assignDealerToBranch(Map<String, dynamic> map) async {
|
|
||||||
MResponse response = await branchRepo.assignDealerToBranch(map);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> removeDealerFromBranch(Map<String, dynamic> map) async {
|
|
||||||
MResponse response = await branchRepo.removeDealerFromBranch(map);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<MResponse> addNewServiceInAppointment(Map<String, dynamic> map) async {
|
|
||||||
MResponse response = await branchRepo.addNewServicesInAppointment(map);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,222 +0,0 @@
|
|||||||
import 'package:car_provider_app/view_models/service_view_model.dart';
|
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:mc_common_app/classes/app_state.dart';
|
|
||||||
import 'package:mc_common_app/extensions/int_extensions.dart';
|
|
||||||
import 'package:mc_common_app/extensions/string_extensions.dart';
|
|
||||||
import 'package:mc_common_app/generated/locale_keys.g.dart';
|
|
||||||
import 'package:mc_common_app/models/general_models/m_response.dart';
|
|
||||||
import 'package:mc_common_app/theme/colors.dart';
|
|
||||||
import 'package:mc_common_app/utils/app_permission_handler.dart';
|
|
||||||
|
|
||||||
import 'package:mc_common_app/utils/enums.dart';
|
|
||||||
import 'package:mc_common_app/utils/utils.dart';
|
|
||||||
import 'package:mc_common_app/widgets/button/show_fill_button.dart';
|
|
||||||
import 'package:mc_common_app/widgets/common_widgets/app_bar.dart';
|
|
||||||
|
|
||||||
import 'package:mc_common_app/widgets/txt_field.dart';
|
|
||||||
|
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
|
||||||
|
|
||||||
class DefineLicensePage extends StatefulWidget {
|
|
||||||
@override
|
|
||||||
State<DefineLicensePage> createState() => _DefineLicensePageState();
|
|
||||||
}
|
|
||||||
|
|
||||||
class _DefineLicensePageState extends State<DefineLicensePage> {
|
|
||||||
late ServiceVM branchVM;
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
// TODO: implement initState
|
|
||||||
super.initState();
|
|
||||||
branchVM = Provider.of<ServiceVM>(context, listen: false);
|
|
||||||
branchVM.getServiceProviderDocument(AppState().getUser.data!.userInfo!.providerId ?? 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
Widget build(BuildContext context) {
|
|
||||||
return Scaffold(
|
|
||||||
appBar: CustomAppBar(
|
|
||||||
title: LocaleKeys.defineLicences.tr(),
|
|
||||||
isRemoveBackButton: false,
|
|
||||||
),
|
|
||||||
body: Consumer<ServiceVM>(builder: (_, model, __) {
|
|
||||||
return Column(
|
|
||||||
children: [
|
|
||||||
Expanded(
|
|
||||||
child: SingleChildScrollView(
|
|
||||||
child: Padding(
|
|
||||||
padding: const EdgeInsets.all(20.0),
|
|
||||||
child: Column(
|
|
||||||
children: [
|
|
||||||
// LocaleKeys.defineLicences.tr().toText20(isBold: true),
|
|
||||||
// 12.height,
|
|
||||||
// LocaleKeys.defineLicenese.tr().toText14(color: MyColors.lightTextColor),
|
|
||||||
20.height,
|
|
||||||
showWidget(model),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.all(12.0),
|
|
||||||
child: ShowFillButton(
|
|
||||||
title: LocaleKeys.continu.tr(),
|
|
||||||
maxWidth: double.infinity,
|
|
||||||
onPressed: () {
|
|
||||||
if (AppState().getUser.data!.userInfo!.roleId == 5) {
|
|
||||||
if (validation(model)) {
|
|
||||||
updateDocument(model);
|
|
||||||
} else {
|
|
||||||
Utils.showToast("All document's are mandatory for Dealership Provider");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
updateDocument(model);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
validation(ServiceVM model) {
|
|
||||||
bool valid = true;
|
|
||||||
model.document!.data!.forEach((element) {
|
|
||||||
if (element.documentUrl == null) {
|
|
||||||
valid = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateDocument(ServiceVM model) async {
|
|
||||||
Utils.showLoading(context);
|
|
||||||
MResponse res = await model.updateDocument(model.document!.data);
|
|
||||||
Utils.hideLoading(context);
|
|
||||||
if (res.messageStatus == 1) {
|
|
||||||
Utils.showToast("Documents uploaded successfully");
|
|
||||||
} else {
|
|
||||||
Utils.showToast(res.message ?? "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Widget showWidget(ServiceVM model) {
|
|
||||||
if (model.state == ViewState.idle) {
|
|
||||||
return model.document!.data!.isEmpty
|
|
||||||
? Text("LocaleKeys.somethingWrong.tr()")
|
|
||||||
: ListView.separated(
|
|
||||||
itemBuilder: (context, index) {
|
|
||||||
return Column(
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
Text(
|
|
||||||
model.document?.data![index].documentName ?? "",
|
|
||||||
style: const TextStyle(
|
|
||||||
fontSize: 16,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
Padding(
|
|
||||||
padding: const EdgeInsets.only(left: 20, right: 20, top: 4, bottom: 8),
|
|
||||||
child: LocaleKeys.enter_licence_detail.tr().toText(fontSize: 14, color: MyColors.lightTextColor, textAlign: TextAlign.center),
|
|
||||||
),
|
|
||||||
TxtField(
|
|
||||||
hint: LocaleKeys.description.tr(),
|
|
||||||
maxLines: 3,
|
|
||||||
isBackgroundEnabled: true,
|
|
||||||
),
|
|
||||||
if ((model.document?.data![index].documentUrl ?? "").toString().isNotEmpty)
|
|
||||||
Column(
|
|
||||||
children: [
|
|
||||||
8.height,
|
|
||||||
(model.document?.data![index].documentUrl ?? "").toString().toText(
|
|
||||||
fontSize: 14,
|
|
||||||
color: MyColors.lightTextColor,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
8.height,
|
|
||||||
InkWell(
|
|
||||||
onTap: () async {
|
|
||||||
int sdkInt = await AppPermissions().getAndroidDeviceInfo();
|
|
||||||
bool isPermissionsAvailable = await requestPermissionGranted(context, sdkInt > 32 ? Permission.photos : Permission.storage);
|
|
||||||
if (isPermissionsAvailable) {
|
|
||||||
model.selectFile(context, index);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
child: Container(
|
|
||||||
width: double.infinity,
|
|
||||||
height: 45,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: Colors.transparent,
|
|
||||||
border: Border.all(color: MyColors.greyACColor, width: 2),
|
|
||||||
borderRadius: const BorderRadius.all(Radius.circular(0)),
|
|
||||||
),
|
|
||||||
child: Row(
|
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
|
||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
|
||||||
children: [
|
|
||||||
const Icon(
|
|
||||||
Icons.attach_file,
|
|
||||||
size: 18,
|
|
||||||
color: MyColors.darkPrimaryColor,
|
|
||||||
),
|
|
||||||
8.width,
|
|
||||||
Text(
|
|
||||||
LocaleKeys.attachFile.tr(),
|
|
||||||
style: const TextStyle(
|
|
||||||
color: MyColors.darkPrimaryColor,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
const Icon(
|
|
||||||
Icons.attach_file,
|
|
||||||
size: 18,
|
|
||||||
color: Colors.transparent,
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
separatorBuilder: (context, index) {
|
|
||||||
return 20.height;
|
|
||||||
},
|
|
||||||
itemCount: model.document!.data!.length,
|
|
||||||
physics: const NeverScrollableScrollPhysics(),
|
|
||||||
shrinkWrap: true,
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
return const Center(
|
|
||||||
child: CircularProgressIndicator(),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// selectFile(int index) async {
|
|
||||||
// FilePickerResult? result = await FilePicker.platform.pickFiles(type: FileType.custom, allowedExtensions: ['png', 'pdf', 'jpeg']);
|
|
||||||
//
|
|
||||||
// if (result != null) {
|
|
||||||
// File file = File(result.files.single.path ?? "");
|
|
||||||
// int sizeInBytes = file.lengthSync();
|
|
||||||
// // double sizeInMb = sizeInBytes / (1024 * 1024);
|
|
||||||
// if (sizeInBytes > 1000) {
|
|
||||||
// Utils.showToast("File is larger then 1KB");
|
|
||||||
// } else {
|
|
||||||
// document!.data![index].document = Utils.convertFileToBase64(file);
|
|
||||||
// document!.data![index].fileExt = Utils.checkFileExt(file.path);
|
|
||||||
// setState(() {
|
|
||||||
// document!.data![index].documentUrl = result.files.single.path ?? "";
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
// // User canceled the picker
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue