From c1eef03f821bee9f7847dde465973da38a6a5c30 Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Wed, 28 Aug 2024 15:19:24 +0300 Subject: [PATCH] pushing changes --- .../general_models/generic_resp_model.dart | 28 ++++ .../branch_detail_model.dart | 34 +++++ lib/repositories/branch_repo.dart | 66 ++++++-- lib/view_models/service_view_model.dart | 144 +++++++++++------- lib/views/user/change_password_page.dart | 2 +- lib/widgets/dropdown/dropdow_field.dart | 25 +-- 6 files changed, 213 insertions(+), 86 deletions(-) diff --git a/lib/models/general_models/generic_resp_model.dart b/lib/models/general_models/generic_resp_model.dart index e98c664..c6b23fd 100644 --- a/lib/models/general_models/generic_resp_model.dart +++ b/lib/models/general_models/generic_resp_model.dart @@ -324,3 +324,31 @@ String toString() { return 'VehiclePostingDamageParts{id: $id, comment: $comment, vehicleImageBase64: $vehicleImageBase64, vehicleDamagePartID: $vehicleDamagePartID, vehiclePostingID: $vehiclePostingID, isActive: $isActive}'; } } + + +class BranchPostingImages { + int? id; + String? imageName; + String? imageUrl; + String? imageStr; + + BranchPostingImages( + {this.id, this.imageName, this.imageUrl, this.imageStr}); + + BranchPostingImages.fromJson(Map json) { + id = json['id']; + imageName = json['imageName']; + imageUrl = json['imageUrl']; + imageStr = json['imageStr']; + } + + Map toJson() { + final Map data = new Map(); + data['id'] = this.id; + data['imageName'] = this.imageName; + data['imageUrl'] = this.imageUrl; + data['imageStr'] = this.imageStr; + return data; + } +} + diff --git a/lib/models/provider_branches_models/branch_detail_model.dart b/lib/models/provider_branches_models/branch_detail_model.dart index af12b1a..edb4af9 100644 --- a/lib/models/provider_branches_models/branch_detail_model.dart +++ b/lib/models/provider_branches_models/branch_detail_model.dart @@ -27,11 +27,27 @@ class BranchDetailModel { double? branchRateAvg; List? branchServices; List? categories; + List? branchAuditTrial; int? countryID; String? countryName; bool isExpanded = false; bool? isFavorite; +//I/flutter (23146): │ "id": 1021, +// I/flutter (23146): │ "serviceProviderID": 10, +// I/flutter (23146): │ "serviceProviderName": "string", +// I/flutter (23146): │ "cityID": 1, +// I/flutter (23146): │ "cityName": "Riyadh", +// I/flutter (23146): │ "branchName": "Al Arouba Cars", +// I/flutter (23146): │ "branchDescription": "des", +// I/flutter (23146): │ "address": "3289 Hilal Bin Omayah St - حي العليا, حي العليا, الرياض, RHOD3289, Saudi Arabia", +// I/flutter (23146): │ "latitude": "24.708521303151027", +// I/flutter (23146): │ "longitude": "46.666924171149724", +// I/flutter (23146): │ "distanceKM": 0.0, +// I/flutter (23146): │ "openTime": "09:00", +// I/flutter (23146): │ "closeTime": "18:00", +// I/flutter (23146): │ "branchStatus": 3, +// I/flutter (23146): │ "branchStatusText": "ApprovedOrActive", BranchDetailModel({ this.id, this.serviceProviderId, @@ -55,6 +71,7 @@ class BranchDetailModel { this.branchStatusLabel, this.branchServices, this.categories, + this.branchAuditTrial, this.countryID, this.countryName, this.isFavorite, @@ -95,7 +112,24 @@ class BranchDetailModel { branchRateAvg = json["branchRateAvg"]; branchServices = json["serviceProviderServices"] == null ? [] : List.from(json["serviceProviderServices"]!.map((x) => ServiceModel.fromJson(x))); categories = []; + branchAuditTrial = json["branchAuditTrial"] == null ? [] : List.from(json["branchAuditTrial"]!.map((x) => BranchAuditTrial.fromJson(x))); isExpanded = false; isFavorite = false; } } + +class BranchAuditTrial { + int? status; + String? comment; + int? createdBy; + String? createdOn; + + BranchAuditTrial({this.status, this.comment, this.createdBy, this.createdOn}); + + BranchAuditTrial.fromJson(Map json) { + status = json['status']; + comment = json['comment']; + createdBy = json['createdBy']; + createdOn = json['createdOn']; + } +} diff --git a/lib/repositories/branch_repo.dart b/lib/repositories/branch_repo.dart index 44c62c6..01e8f9c 100644 --- a/lib/repositories/branch_repo.dart +++ b/lib/repositories/branch_repo.dart @@ -17,9 +17,27 @@ import 'package:mc_common_app/models/provider_branches_models/provider_profile_m import 'package:mc_common_app/models/services_models/item_model.dart'; abstract class BranchRepo { - Future createBranch(String branchName, String branchDescription, String cityId, String address, String latitude, String longitude); + Future createBranch({ + required String branchName, + required String branchDescription, + required int cityId, + required String address, + required double latitude, + required double longitude, + required List imagesList, + }); - Future updateBranch(int id, String branchName, String branchDescription, String cityId, String address, String latitude, String longitude, {bool isNeedToDelete = true}); + Future updateBranch({ + required int branchId, + required String branchName, + required String branchDescription, + required int cityId, + required String address, + required String latitude, + required String longitude, + required List imagesList, + bool isNeedToDelete = true, + }); Future fetchAllBranches(); @@ -91,16 +109,36 @@ class BranchRepoImp implements BranchRepo { AppState appState = injector.get(); @override - Future createBranch(String branchName, String branchDescription, String cityId, String address, String latitude, String longitude) async { + Future createBranch({ + required String branchName, + required String branchDescription, + required int cityId, + required String address, + required double latitude, + required double longitude, + required List imagesList, + }) async { + List serviceProviderBranchImages = []; + for (var element in imagesList) { + var imageMap = { + "id": element.id ?? 0, + "imageName": element.imageName, + "imageUrl": element.imageUrl, + "imageStr": element.imageStr, + }; + serviceProviderBranchImages.add(imageMap); + } + var postParams = { "serviceProviderID": AppState().getUser.data?.userInfo?.providerId ?? "", "branchName": branchName, "branchDescription": branchDescription, - "cityID": cityId, + "cityID": cityId.toString(), "address": address, "latitude": latitude, "longitude": longitude, - "isActive": true + "isActive": true, + "serviceProviderBranchImages": serviceProviderBranchImages, }; String t = AppState().getUser.data!.accessToken ?? ""; return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createProviderBranch, postParams, token: t); @@ -177,14 +215,24 @@ class BranchRepoImp implements BranchRepo { } @override - Future updateBranch(int id, String branchName, String branchDescription, String cityId, String address, String latitude, String longitude, {bool isNeedToDelete = true}) async { + Future updateBranch({ + required int branchId, + required String branchName, + required String branchDescription, + required int cityId, + required String address, + required String latitude, + required String longitude, + required List imagesList, + bool isNeedToDelete = true, + }) async { String lat = "0", long = "0"; try { - lat = latitude.substring(0, 9); - long = longitude.substring(0, 9); + lat = latitude.toString().substring(0, 9); + long = longitude.toString().substring(0, 9); } catch (e) {} var postParams = { - "id": id, + "id": branchId, "serviceProviderID": AppState().getUser.data?.userInfo?.providerId ?? "", "branchName": branchName, "branchDescription": branchDescription, diff --git a/lib/view_models/service_view_model.dart b/lib/view_models/service_view_model.dart index d9f9212..7cbec07 100644 --- a/lib/view_models/service_view_model.dart +++ b/lib/view_models/service_view_model.dart @@ -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 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 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 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 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 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 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 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 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()); } } } diff --git a/lib/views/user/change_password_page.dart b/lib/views/user/change_password_page.dart index d35e3f5..10c1a20 100644 --- a/lib/views/user/change_password_page.dart +++ b/lib/views/user/change_password_page.dart @@ -36,7 +36,7 @@ class _ChangePasswordPageState extends State { child: Container( // width: double.infinity, // height: double.infinity, - padding: EdgeInsets.all(20), + padding: const EdgeInsets.all(20), child: Column( children: [ LocaleKeys.enterNewPassword.tr().toText(height: 23 / 24, fontSize: 24, letterSpacing: -1.44,), diff --git a/lib/widgets/dropdown/dropdow_field.dart b/lib/widgets/dropdown/dropdow_field.dart index e94aa47..dbe5e47 100644 --- a/lib/widgets/dropdown/dropdow_field.dart +++ b/lib/widgets/dropdown/dropdow_field.dart @@ -3,6 +3,7 @@ import 'package:mc_common_app/extensions/string_extensions.dart'; import 'package:mc_common_app/theme/colors.dart'; import 'package:mc_common_app/utils/utils.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; +import 'package:sizer/sizer.dart'; class DropValue { int id; @@ -30,9 +31,7 @@ class DropdownField extends StatefulWidget { final TextStyle? textStyle; final bool isSelectAble; - const DropdownField(this.onSelect, - {Key? key, this.hint, this.list, this.dropdownValue, this.errorValue = "", this.showAppointmentPickerVariant = false, this.textStyle, this.isSelectAble = true}) - : super(key: key); + const DropdownField(this.onSelect, {Key? key, this.hint, this.list, this.dropdownValue, this.errorValue = "", this.showAppointmentPickerVariant = false, this.textStyle, this.isSelectAble = true}) : super(key: key); @override State createState() => _DropdownFieldState(); @@ -56,9 +55,7 @@ class _DropdownFieldState extends State { return Column( children: [ Container( - decoration: widget.showAppointmentPickerVariant ? null : Utils - .containerColorRadiusBorderWidth( - MyColors.white, 0, MyColors.darkPrimaryColor, 2), + decoration: widget.showAppointmentPickerVariant ? null : Utils.containerColorRadiusBorderWidth(MyColors.white, 0, MyColors.darkPrimaryColor, 2), margin: const EdgeInsets.all(0), padding: const EdgeInsets.only(left: 8, right: 8), width: widget.showAppointmentPickerVariant ? 170 : null, @@ -70,15 +67,8 @@ class _DropdownFieldState extends State { iconEnabledColor: borderColor, iconDisabledColor: borderColor, isExpanded: true, - style: widget.showAppointmentPickerVariant - ? widget.textStyle - : const TextStyle( - color: Colors.black, fontWeight: FontWeight.w600, fontSize: 15), - hint: (widget.hint ?? "").toText( - color: widget.showAppointmentPickerVariant - ? Colors.black - : borderColor, - fontSize: widget.showAppointmentPickerVariant ? 18 : 15), + style: TextStyle(color: borderColor, fontFamily: 'Poppins', fontSize: 13.sp), + hint: (widget.hint ?? "").toText(color: borderColor, fontSize: 13.sp), underline: Container(height: 0), onChanged: (DropValue? newValue) { setState(() { @@ -87,12 +77,11 @@ class _DropdownFieldState extends State { }); }, items: (widget.list ?? defaultV).map>( - (DropValue value) { + (DropValue value) { return DropdownMenuItem( value: value, enabled: value.isEnabled ?? true, - child: value.value.toText(fontSize: 15, - color: value.isEnabled == false ? Colors.black38 : null), + child: value.value.toText(fontSize: 13.sp, color: value.isEnabled == false ? Colors.black38 : null), ); }, ).toList(),