From 31a9b71b8319008c0b01aa87f89bcdb86b4cc67e Mon Sep 17 00:00:00 2001 From: Faiz Hashmi Date: Wed, 28 Aug 2024 09:36:10 +0300 Subject: [PATCH] Model Refactoring --- assets/langs/ar-SA.json | 11 +- assets/langs/en-US.json | 10 +- lib/api/api_client.dart | 1 - lib/config/routes.dart | 61 ++- lib/extensions/string_extensions.dart | 2 + lib/generated/codegen_loader.g.dart | 20 +- lib/generated/locale_keys.g.dart | 8 + .../chat_models/chat_message_model.dart | 4 + lib/models/general_models/m_response.dart | 36 -- .../branch_detail_model.dart | 105 +++-- .../provider_profile_model.dart | 49 +- lib/repositories/appointment_repo.dart | 51 +- lib/repositories/branch_repo.dart | 88 ++-- lib/repositories/items_repo.dart | 14 +- lib/repositories/request_repo.dart | 1 + lib/repositories/schedule_repo.dart | 32 +- lib/repositories/subscription_repo.dart | 17 +- lib/repositories/user_repo.dart | 14 +- lib/services/common_services.dart | 39 +- lib/utils/utils.dart | 51 +- lib/view_models/appointments_view_model.dart | 28 +- lib/view_models/requests_view_model.dart | 23 +- lib/view_models/service_view_model.dart | 444 ++++++------------ lib/view_models/subscriptions_view_model.dart | 45 +- lib/view_models/user_view_model.dart | 7 +- lib/views/advertisement/ads_detail_view.dart | 2 +- .../ads_images_corousel_widget.dart | 26 +- lib/views/appointments/pick_items_view.dart | 4 +- lib/views/requests/create_request_page.dart | 202 ++------ .../provider_license_page.dart | 16 +- .../setting_options_language.dart | 249 +++++----- .../common_widgets/branch_details_card.dart | 122 +++++ .../common_widgets/provider_details_card.dart | 146 +++--- lib/widgets/extensions/extensions_widget.dart | 74 ++- 34 files changed, 1001 insertions(+), 1001 deletions(-) delete mode 100644 lib/models/general_models/m_response.dart create mode 100644 lib/widgets/common_widgets/branch_details_card.dart diff --git a/assets/langs/ar-SA.json b/assets/langs/ar-SA.json index 32b9472..c4069ae 100644 --- a/assets/langs/ar-SA.json +++ b/assets/langs/ar-SA.json @@ -582,5 +582,14 @@ "noUpcomingAppointments": "لا يوجد موعد قادم متاح", "addNewAppointment": "إضافة موعد جديد", "myNearbyBranches": "فروعي القريبة", - "myRecentBranches": "فروعي الأخيرة" + "myRecentBranches": "فروعي الأخيرة", + "favoriteList": "قائمة المفضلة", + "noReviewsBranch": "هذا الفرع لا يوجد لديه تعليقات.", + "readLess": "اقرأ أقل", + "readMoreReviews": "اقرأ المزيد من التقييمات", + "noProvidersInFav": "ليس لديك أي مقدمي خدمات في المفضلة.", + "providerHasNoBranches": "هذا المزود ليس لديه فروع حتى الآن.", + "totalBranches": "إجمالي الفروع", + "memberSince": "عضو منذ" + } \ No newline at end of file diff --git a/assets/langs/en-US.json b/assets/langs/en-US.json index 5698e44..87cbe08 100644 --- a/assets/langs/en-US.json +++ b/assets/langs/en-US.json @@ -583,5 +583,13 @@ "noUpcomingAppointments": "No Upcoming Appointment Available.", "addNewAppointment": "Add New Appointment", "myNearbyBranches": "My Nearby Branches", - "myRecentBranches": "My Recent Branches" + "myRecentBranches": "My Recent Branches", + "favoriteList": "Favourite List", + "noReviewsBranch": "This branch has no reviews.", + "readLess": "Read Less", + "readMoreReviews": "Read More Reviews", + "noProvidersInFav": "You have no providers in Favourites.", + "providerHasNoBranches": "This Provider has no branches yet.", + "totalBranches": "Total Branches", + "memberSince": "Member Since" } \ No newline at end of file diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index ceafccf..2c0db39 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -245,7 +245,6 @@ class ApiClientImp implements ApiClient { var response = await _get(Uri.parse(url), headers: headers0).timeout(const Duration(seconds: 60)); if (!kReleaseMode) { - logger.i("Url:$url"); logger.i(jsonDecode(response.body)); } if (response.statusCode >= 200 && response.statusCode < 500) { diff --git a/lib/config/routes.dart b/lib/config/routes.dart index 9192a9c..84b8932 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -86,6 +86,7 @@ class AppRoutes { static const String branchDetailView = "/branchDetailPage"; static const String branchSearchFilterPage = "/branchSearchFilterPage"; static const String providerProfileView = "/providerProfilePage"; + static const String favoriteListView = "/favoriteListView"; // Subscriptions static const String mySubscriptionsPage = "/mySubscriptionsPage"; @@ -127,12 +128,28 @@ class AppRoutes { forgetPassword: (context) => const ForgetPasswordPage(), loginVerification: (context) => const LoginVerificationPage(), loginWithPassword: (context) => const LoginWithPassword(), - loginMethodSelection: (context) => LoginMethodSelectionPage(ModalRoute.of(context)!.settings.arguments as String), - completeProfile: (context) => CompleteProfilePage(ModalRoute.of(context)!.settings.arguments as RegisterUserRespModel), + loginMethodSelection: (context) => + LoginMethodSelectionPage(ModalRoute + .of(context)! + .settings + .arguments as String), + completeProfile: (context) => + CompleteProfilePage(ModalRoute + .of(context)! + .settings + .arguments as RegisterUserRespModel), verifyPassword: (context) => VerifyPasswordPage(), - confirmNewPasswordPage: (context) => ConfirmNewPasswordPage(ModalRoute.of(context)!.settings.arguments as String), + confirmNewPasswordPage: (context) => + ConfirmNewPasswordPage(ModalRoute + .of(context)! + .settings + .arguments as String), changePassword: (context) => const ChangePasswordPage(), - forgetPasswordMethodPage: (context) => ForgetPasswordMethodPage(ModalRoute.of(context)!.settings.arguments as String), + forgetPasswordMethodPage: (context) => + ForgetPasswordMethodPage(ModalRoute + .of(context)! + .settings + .arguments as String), changeMobilePage: (context) => ChangeMobilePage(), changeEmailPage: (context) => const ChangeEmailPage(), editAccountPage: (context) => const EditAccountPage(), @@ -142,17 +159,41 @@ class AppRoutes { providerLicensePage: (context) => ProviderLicensePage(), // common pages - AppRoutes.adsDetailView: (context) => AdsDetailView(adDetails: ModalRoute.of(context)!.settings.arguments as AdDetailsModel), + AppRoutes.adsDetailView: (context) => + AdsDetailView(adDetails: ModalRoute + .of(context)! + .settings + .arguments as AdDetailsModel), AppRoutes.createAdView: (context) => const CreateAdView(), AppRoutes.adsFilterView: (context) => const AdsFilterView(), - AppRoutes.selectAdTypeView: (context) => SelectAdTypeView(arguments: ModalRoute.of(context)!.settings.arguments as List), - AppRoutes.chatView: (context) => ChatView(chatViewArguments: ModalRoute.of(context)!.settings.arguments as ChatViewArguments), - AppRoutes.offersListPage: (context) => OfferListPage(offerListPageArguments: ModalRoute.of(context)!.settings.arguments as OfferListPageArguments), - AppRoutes.adsBuyerChatsListView: (context) => AdsBuyerChatsView(buyersListViewArguments: ModalRoute.of(context)!.settings.arguments as List), + AppRoutes.selectAdTypeView: (context) => + SelectAdTypeView(arguments: ModalRoute + .of(context)! + .settings + .arguments as List), + AppRoutes.chatView: (context) => + ChatView(chatViewArguments: ModalRoute + .of(context)! + .settings + .arguments as ChatViewArguments), + AppRoutes.offersListPage: (context) => + OfferListPage(offerListPageArguments: ModalRoute + .of(context)! + .settings + .arguments as OfferListPageArguments), + AppRoutes.adsBuyerChatsListView: (context) => + AdsBuyerChatsView(buyersListViewArguments: ModalRoute + .of(context)! + .settings + .arguments as List), AppRoutes.createRequestPage: (context) => const CreateRequestPage(), AppRoutes.settingOptionsFaqs: (context) => const SettingOptionsFAQs(), AppRoutes.settingOptionsInviteFriends: (context) => const SettingOptionsInviteFriends(), - AppRoutes.paymentMethodsView: (context) => PaymentMethodsView(paymentType: ModalRoute.of(context)!.settings.arguments as PaymentTypes), + AppRoutes.paymentMethodsView: (context) => + PaymentMethodsView(paymentType: ModalRoute + .of(context)! + .settings + .arguments as PaymentTypes), }; } diff --git a/lib/extensions/string_extensions.dart b/lib/extensions/string_extensions.dart index bacf8a1..dd6a281 100644 --- a/lib/extensions/string_extensions.dart +++ b/lib/extensions/string_extensions.dart @@ -17,12 +17,14 @@ extension EmailValidator on String { FontWeight? fontWeight, double? height, Color? decorationColor, + TextOverflow? overflow, int? maxLines}) => AutoSizeText( this, textAlign: textAlign, maxLines: maxLines, style: TextStyle( + overflow: overflow, fontStyle: isItalic ? FontStyle.italic : null, height: height, decoration: isUnderLine ? TextDecoration.underline : textDecoration ?? TextDecoration.none, diff --git a/lib/generated/codegen_loader.g.dart b/lib/generated/codegen_loader.g.dart index 9f71ab2..069ffe0 100644 --- a/lib/generated/codegen_loader.g.dart +++ b/lib/generated/codegen_loader.g.dart @@ -598,7 +598,15 @@ class CodegenLoader extends AssetLoader{ "noUpcomingAppointments": "لا يوجد موعد قادم متاح", "addNewAppointment": "إضافة موعد جديد", "myNearbyBranches": "فروعي القريبة", - "myRecentBranches": "فروعي الأخيرة" + "myRecentBranches": "فروعي الأخيرة", + "favoriteList": "قائمة المفضلة", + "noReviewsBranch": "هذا الفرع لا يوجد لديه تعليقات.", + "readLess": "اقرأ أقل", + "readMoreReviews": "اقرأ المزيد من التقييمات", + "noProvidersInFav": "ليس لديك أي مقدمي خدمات في المفضلة.", + "providerHasNoBranches": "هذا المزود ليس لديه فروع حتى الآن.", + "totalBranches": "إجمالي الفروع", + "memberSince": "عضو منذ" }; static const Map en_US = { "firstTimeLogIn": "First Time Log In", @@ -1185,7 +1193,15 @@ static const Map en_US = { "noUpcomingAppointments": "No Upcoming Appointment Available.", "addNewAppointment": "Add New Appointment", "myNearbyBranches": "My Nearby Branches", - "myRecentBranches": "My Recent Branches" + "myRecentBranches": "My Recent Branches", + "favoriteList": "Favourite List", + "noReviewsBranch": "This branch has no reviews.", + "readLess": "Read Less", + "readMoreReviews": "Read More Reviews", + "noProvidersInFav": "You have no providers in Favourites.", + "providerHasNoBranches": "This Provider has no branches yet.", + "totalBranches": "Total Branches", + "memberSince": "Member Since" }; static const Map> mapLocales = {"ar_SA": ar_SA, "en_US": en_US}; } diff --git a/lib/generated/locale_keys.g.dart b/lib/generated/locale_keys.g.dart index 4c9ac7e..19f32f9 100644 --- a/lib/generated/locale_keys.g.dart +++ b/lib/generated/locale_keys.g.dart @@ -562,5 +562,13 @@ abstract class LocaleKeys { static const addNewAppointment = 'addNewAppointment'; static const myNearbyBranches = 'myNearbyBranches'; static const myRecentBranches = 'myRecentBranches'; + static const favoriteList = 'favoriteList'; + static const noReviewsBranch = 'noReviewsBranch'; + static const readLess = 'readLess'; + static const readMoreReviews = 'readMoreReviews'; + static const noProvidersInFav = 'noProvidersInFav'; + static const providerHasNoBranches = 'providerHasNoBranches'; + static const totalBranches = 'totalBranches'; + static const memberSince = 'memberSince'; } diff --git a/lib/models/chat_models/chat_message_model.dart b/lib/models/chat_models/chat_message_model.dart index 7702053..82b0257 100644 --- a/lib/models/chat_models/chat_message_model.dart +++ b/lib/models/chat_models/chat_message_model.dart @@ -104,3 +104,7 @@ class OfferRequestCommentModel { OfferRequestCommentModel({this.index, this.title, this.isSelected}); } + + + + diff --git a/lib/models/general_models/m_response.dart b/lib/models/general_models/m_response.dart deleted file mode 100644 index 856de8e..0000000 --- a/lib/models/general_models/m_response.dart +++ /dev/null @@ -1,36 +0,0 @@ -// To parse this JSON data, do -// -// final mResponse = mResponseFromJson(jsonString); - -import 'dart:convert'; - -MResponse mResponseFromJson(String str) => MResponse.fromJson(json.decode(str)); - -String mResponseToJson(MResponse data) => json.encode(data.toJson()); - -class MResponse { - MResponse({ - this.totalItemsCount, - this.messageStatus, - this.message, - this.data, - }); - - int? totalItemsCount; - int? messageStatus; - String? message; - dynamic data; - - factory MResponse.fromJson(Map json) => MResponse( - totalItemsCount: json["totalItemsCount"], - messageStatus: json["messageStatus"], - message: json["message"], - data: json["data"], - ); - - Map toJson() => { - "totalItemsCount": totalItemsCount, - "messageStatus": messageStatus, - "message": message, - }; -} diff --git a/lib/models/provider_branches_models/branch_detail_model.dart b/lib/models/provider_branches_models/branch_detail_model.dart index ba0d747..af12b1a 100644 --- a/lib/models/provider_branches_models/branch_detail_model.dart +++ b/lib/models/provider_branches_models/branch_detail_model.dart @@ -1,37 +1,42 @@ import 'package:mc_common_app/extensions/string_extensions.dart'; +import 'package:mc_common_app/models/advertisment_models/ad_details_model.dart'; import 'package:mc_common_app/models/provider_branches_models/profile/categroy.dart'; import 'package:mc_common_app/models/services_models/service_model.dart'; import 'package:mc_common_app/utils/enums.dart'; class BranchDetailModel { - final int? id; - final int? serviceProviderId; - final String? serviceProviderName; - final String? branchName; - final String? branchDescription; - final int? cityId; - final String? cityName; - final String? address; - final String? latitude; - final String? longitude; - final double? distanceKm; - final String? openTime; - final String? closeTime; - final BranchStatusEnum? branchStatus; - final int? statusId; - final String? statusText; - final double? branchRateAvg; - final List? branchServices; + int? id; + int? serviceProviderId; + String? serviceProviderName; + String? branchProfileImage; + String? branchName; + String? branchDescription; + int? cityId; + String? cityName; + String? address; + String? latitude; + String? longitude; + double? distanceKm; + String? openTime; + String? closeTime; + BranchStatusEnum? branchStatus; + List? branchImages; + int? statusId; + String? statusText; + String? branchStatusLabel; + double? branchRateAvg; + List? branchServices; List? categories; int? countryID; String? countryName; - bool isExpanded; + bool isExpanded = false; bool? isFavorite; BranchDetailModel({ this.id, this.serviceProviderId, this.serviceProviderName, + this.branchProfileImage, this.branchName, this.branchDescription, this.cityId, @@ -43,9 +48,11 @@ class BranchDetailModel { this.openTime, this.closeTime, this.branchStatus, + this.branchImages, this.branchRateAvg, this.statusId, this.statusText, + this.branchStatusLabel, this.branchServices, this.categories, this.countryID, @@ -54,27 +61,41 @@ class BranchDetailModel { required this.isExpanded, }); - factory BranchDetailModel.fromJson(Map json) => BranchDetailModel( - id: json["id"], - serviceProviderId: json["serviceProviderID"], - serviceProviderName: json["serviceProviderName"], - branchName: json["branchName"], - branchDescription: json["branchDescription"], - cityId: json["cityID"], - cityName: json["cityName"], - address: json["address"], - latitude: json["latitude"], - longitude: json["longitude"], - distanceKm: json["distanceKM"]?.toDouble(), - openTime: json["openTime"], - closeTime: json["closeTime"], - branchStatus: json.containsKey("branchStatus") ? (json['branchStatus'] as int).toBranchStatusEnum() : null, - statusId: json["branchStatus"], - statusText: json["statusText"], - branchRateAvg: json["branchRateAvg"], - branchServices: json["serviceProviderServices"] == null ? [] : List.from(json["serviceProviderServices"]!.map((x) => ServiceModel.fromJson(x))), - categories: [], - isExpanded: false, - isFavorite: false, - ); + List populateBranchImages(value) { + List images = []; + if (value != null) { + value.forEach((v) { + images.add(AdImage.fromJson(v)); + }); + } + return images; + } + + BranchDetailModel.fromJson(Map json) { + List images = populateBranchImages(json["serviceProviderBranchImage"]); + id = json["id"]; + serviceProviderId = json["serviceProviderID"]; + branchProfileImage = images.isNotEmpty ? images.first.imageUrl ?? "" : null; + serviceProviderName = json["serviceProviderName"]; + branchName = json["branchName"]; + branchDescription = json["branchDescription"]; + cityId = json["cityID"]; + cityName = json["cityName"]; + address = json["address"]; + latitude = json["latitude"]; + longitude = json["longitude"]; + distanceKm = json["distanceKM"]?.toDouble(); + openTime = json["openTime"]; + closeTime = json["closeTime"]; + branchStatus = json.containsKey("branchStatus") ? (json['branchStatus'] as int).toBranchStatusEnum() : null; + statusId = json["branchStatus"]; + branchImages = images; + statusText = json["statusText"]; + branchStatusLabel = json["branchStatusText"]; + branchRateAvg = json["branchRateAvg"]; + branchServices = json["serviceProviderServices"] == null ? [] : List.from(json["serviceProviderServices"]!.map((x) => ServiceModel.fromJson(x))); + categories = []; + isExpanded = false; + isFavorite = false; + } } diff --git a/lib/models/provider_branches_models/provider_profile_model.dart b/lib/models/provider_branches_models/provider_profile_model.dart index cbcefae..0ad6d75 100644 --- a/lib/models/provider_branches_models/provider_profile_model.dart +++ b/lib/models/provider_branches_models/provider_profile_model.dart @@ -4,37 +4,80 @@ class ProviderProfileModel { ProviderProfileModel({ this.id, this.companyName, + this.name, this.countryName, this.companyDescription, this.allDocStatus, this.isValidSubscription, this.userId, + this.memberSince, this.serviceProviderBranch, this.countryID, this.isFavorite, + this.providerID, + this.noOfBranches, + this.customerID, }); final int? id; final String? companyName; - final String? countryName; - int? countryID; final String? companyDescription; + int? countryID; + final String? countryName; final int? allDocStatus; final bool? isValidSubscription; - bool? isFavorite; + final String? name; final String? userId; + final String? memberSince; + bool? isFavorite; + final int? providerID; + final int? customerID; + final int? noOfBranches; final List? serviceProviderBranch; factory ProviderProfileModel.fromJson(Map json) => ProviderProfileModel( id: json["id"], companyName: json["companyName"], + name: json["name"], countryName: json["countryName"], countryID: json["countryID"], companyDescription: json["companyDescription"], allDocStatus: json["allDocStatus"], isValidSubscription: json["isValidSubscription"], userId: json["userID"], + memberSince: json["memberSince"] ?? "", + providerID: json["providerID"] ?? 0, + customerID: json["customerID"] ?? 0, + noOfBranches: json["noOfBranches"] ?? (json["serviceProviderBranch"] != null ? (json["serviceProviderBranch"] as List).length : 0), isFavorite: json["isFavourite"] ?? false, serviceProviderBranch: json["serviceProviderBranch"] == null ? null : List.from(json["serviceProviderBranch"].map((x) => BranchDetailModel.fromJson(x))), ); } + +// { +// "id": 10, +// "companyName": "string", +// "companyDescription": "", +// "countryID": 1, +// "countryName": "Saudi Arabia", +// "allDocStatus": 0, +// "isValidSubscription": true, +// "name": null, +// "userID": "88e2e2e8-9a6d-4f97-b05c-08dc7e4513b3", +// } +// +// { +// "id": 0, +// "companyName": "string", +// "companyDescription": "", +// "countryID": 1, +// "countryName": "string", +// "allDocStatus": 3, +// "isValidSubscription": true, +// "name": "Mirza Shafique", +// "userID": "7db5e1ae-6de4-47d7-984b-08db2842f899", +// "providerID": 2, +// "customerID": 6, +// "noOfBranches": 12, +// "memberSince": "2024-08-22T11:36:46.41" +// } diff --git a/lib/repositories/appointment_repo.dart b/lib/repositories/appointment_repo.dart index 649860d..9803fe4 100644 --- a/lib/repositories/appointment_repo.dart +++ b/lib/repositories/appointment_repo.dart @@ -8,7 +8,6 @@ import 'package:mc_common_app/models/appointments_models/appointment_list_model. import 'package:mc_common_app/models/appointments_models/schedule_model.dart'; import 'package:mc_common_app/models/appointments_models/service_schedule_model.dart'; import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; import 'package:mc_common_app/models/provider_branches_models/profile/services.dart'; abstract class AppointmentRepo { @@ -21,25 +20,25 @@ abstract class AppointmentRepo { List? branchIdsList, }); - Future updateAppointmentStatus(Map map); + Future updateAppointmentStatus(Map map); - Future updateAppointmentPaymentStatus(Map map); + Future updateAppointmentPaymentStatus(Map map); - Future getAppointmentSlots(Map map); + Future getAppointmentSlots(Map map); - Future createMergeAppointment(Map map); + Future createMergeAppointment(Map map); Future getAllServices(String branchId); - Future createSchedule(Map map); + Future createSchedule(Map map); - Future addServicesInSchedule(Map map); + Future addServicesInSchedule(Map map); - Future updateSchedule(Map map); + Future updateSchedule(Map map); Future> getSchedules(String branchId); - Future updateServicesInSchedule(Map map); + Future updateServicesInSchedule(Map map); Future> mergeServiceIntoAvailableSchedules({ required List serviceItemIdsForHome, @@ -65,15 +64,15 @@ class AppointmentRepoImp implements AppointmentRepo { } @override - Future createSchedule(Map map) async { + Future createSchedule(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createSchedule, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createSchedule, map, token: t); } @override - Future addServicesInSchedule(Map map) async { + Future addServicesInSchedule(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createGroup, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createGroup, map, token: t); } @override @@ -92,15 +91,15 @@ class AppointmentRepoImp implements AppointmentRepo { } @override - Future updateSchedule(Map map) async { + Future updateSchedule(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateSchedule, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateSchedule, map, token: t); } @override - Future updateServicesInSchedule(Map map) async { + Future updateServicesInSchedule(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateGroup, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateGroup, map, token: t); } Future> mergeServiceIntoAvailableSchedules({ @@ -222,11 +221,11 @@ class AppointmentRepoImp implements AppointmentRepo { } @override - Future getAppointmentSlots(Map map) async { + Future getAppointmentSlots(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - MResponse adsGenericModel = await apiClient.getJsonForObject( - (json) => MResponse.fromJson(json), + GenericRespModel adsGenericModel = await apiClient.getJsonForObject( + (json) => GenericRespModel.fromJson(json), ApiConsts.getAppointmentSlots, token: t, queryParameters: map, @@ -236,21 +235,21 @@ class AppointmentRepoImp implements AppointmentRepo { } @override - Future updateAppointmentPaymentStatus(Map map) async { + Future updateAppointmentPaymentStatus(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateAppointmentPaymentStatus, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateAppointmentPaymentStatus, map, token: t); } @override - Future updateAppointmentStatus(Map map) async { + Future updateAppointmentStatus(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateAppointmentStatus, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateAppointmentStatus, map, token: t); } @override - Future createMergeAppointment(Map map) async { + Future createMergeAppointment(Map map) async { String t = appState.getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createMergeAppointment, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createMergeAppointment, map, token: t); } diff --git a/lib/repositories/branch_repo.dart b/lib/repositories/branch_repo.dart index 4db4ced..44c62c6 100644 --- a/lib/repositories/branch_repo.dart +++ b/lib/repositories/branch_repo.dart @@ -5,8 +5,6 @@ import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/config/dependency_injection.dart'; import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; - import 'package:flutter/cupertino.dart'; import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart'; import 'package:mc_common_app/models/provider_branches_models/branch_review_model.dart'; @@ -19,9 +17,9 @@ 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(String branchName, String branchDescription, String cityId, String address, String latitude, String longitude); - Future updateBranch(int id, String branchName, String branchDescription, String cityId, String address, String latitude, String longitude, {bool isNeedToDelete = true}); + Future updateBranch(int id, String branchName, String branchDescription, String cityId, String address, String latitude, String longitude, {bool isNeedToDelete = true}); Future fetchAllBranches(); @@ -31,33 +29,33 @@ abstract class BranchRepo { Future fetchProviderServices(String branchID, String serviceCategoryId); - Future createNewService(List> map); + Future createNewService(List> map); Future getServiceProviderDocument(dynamic userId); - Future serviceProviderDocumentsUpdate(List? documents); + Future serviceProviderDocumentsUpdate(List? documents); Future getBranchAndServices(); Future> getAllProvidersWitheBasicData(); - Future createService(List> map); + Future createService(List> map); - Future updateService(List> map); + Future updateService(List> map); - Future getMatchedServices(int oldBranchId, int newBranchId, int categoryId); + Future getMatchedServices(int oldBranchId, int newBranchId, int categoryId); - Future duplicateItems(Map map); + Future duplicateItems(Map map); - Future getAllProviderDealers(Map map); + Future getAllProviderDealers(Map map); - Future getBranchUsers(Map map); + Future getBranchUsers(Map map); - Future assignDealerToBranch(Map map); + Future assignDealerToBranch(Map map); - Future removeDealerFromBranch(Map map); + Future removeDealerFromBranch(Map map); - Future addNewServicesInAppointment(Map map); + Future addNewServicesInAppointment(Map map); Future> getAllNearBranchAndServices(); @@ -85,7 +83,7 @@ abstract class BranchRepo { Future removeProviderFromFavourite({required int providerID}); - Future> getMyFavoriteProviders(); + Future> getMyFavoriteProviders(); } class BranchRepoImp implements BranchRepo { @@ -93,7 +91,7 @@ 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(String branchName, String branchDescription, String cityId, String address, String latitude, String longitude) async { var postParams = { "serviceProviderID": AppState().getUser.data?.userInfo?.providerId ?? "", "branchName": branchName, @@ -105,7 +103,7 @@ class BranchRepoImp implements BranchRepo { "isActive": true }; String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createProviderBranch, postParams, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createProviderBranch, postParams, token: t); } @override @@ -130,9 +128,9 @@ class BranchRepoImp implements BranchRepo { } @override - Future createNewService(List> map) async { + Future createNewService(List> map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderServiceCreate, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.serviceProviderServiceCreate, map, token: t); } @override @@ -146,7 +144,7 @@ class BranchRepoImp implements BranchRepo { } @override - Future serviceProviderDocumentsUpdate(List? documents) async { + Future serviceProviderDocumentsUpdate(List? documents) async { List> map = []; for (int i = 0; i < documents!.length; i++) { if (documents[i].document != null) { @@ -155,7 +153,7 @@ class BranchRepoImp implements BranchRepo { } } String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderDocumentUpdate, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.serviceProviderDocumentUpdate, map, token: t); } @override @@ -179,7 +177,7 @@ 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(int id, String branchName, String branchDescription, String cityId, String address, String latitude, String longitude, {bool isNeedToDelete = true}) async { String lat = "0", long = "0"; try { lat = latitude.substring(0, 9); @@ -197,60 +195,60 @@ class BranchRepoImp implements BranchRepo { "isActive": isNeedToDelete }; String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateProviderBranch, postParams, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateProviderBranch, postParams, token: t); } @override - Future createService(List> map) async { + Future createService(List> map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderServiceCreate, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.serviceProviderServiceCreate, map, token: t); } @override - Future updateService(List> map) async { + Future updateService(List> map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.serviceProviderServiceUpdate, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.serviceProviderServiceUpdate, map, token: t); } @override - Future getMatchedServices(int oldBranchId, int newBranchId, int categoryId) async { + Future getMatchedServices(int oldBranchId, int newBranchId, int categoryId) async { var postParams = { "ProviderBranchIDExisted": oldBranchId.toString(), "ProviderBranchIDNew": newBranchId.toString(), "CategoryID": categoryId.toString(), }; String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.getJsonForObject((json) => MResponse.fromJson(json), ApiConsts.getMatchedServices, queryParameters: postParams, token: t); + return await apiClient.getJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.getMatchedServices, queryParameters: postParams, token: t); } @override - Future duplicateItems(Map map) async { + Future duplicateItems(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.duplicateItems, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.duplicateItems, map, token: t); } @override - Future getAllProviderDealers(Map map) async { + Future getAllProviderDealers(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.getJsonForObject((json) => MResponse.fromJson(json), ApiConsts.getAllProviderDealers, queryParameters: map, token: t); + return await apiClient.getJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.getAllProviderDealers, queryParameters: map, token: t); } @override - Future getBranchUsers(Map map) async { + Future getBranchUsers(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.getJsonForObject((json) => MResponse.fromJson(json), ApiConsts.getBranchUser, queryParameters: map, token: t); + return await apiClient.getJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.getBranchUser, queryParameters: map, token: t); } @override - Future assignDealerToBranch(Map map) async { + Future assignDealerToBranch(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.assignDealerToBranch, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.assignDealerToBranch, map, token: t); } @override - Future removeDealerFromBranch(Map map) async { + Future removeDealerFromBranch(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.removeDealerFromBranch, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.removeDealerFromBranch, map, token: t); } @override @@ -265,9 +263,9 @@ class BranchRepoImp implements BranchRepo { } @override - Future addNewServicesInAppointment(Map map) async { + Future addNewServicesInAppointment(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await apiClient.postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.addNewServicesInAppointment, map, token: t); + return await apiClient.postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.addNewServicesInAppointment, map, token: t); } @override @@ -412,7 +410,7 @@ class BranchRepoImp implements BranchRepo { } @override - Future> getMyFavoriteProviders() async { + Future> getMyFavoriteProviders() async { final customerID = appState.getUser.data!.userInfo!.customerId; var postParams = {"customerID": customerID.toString()}; @@ -423,7 +421,7 @@ class BranchRepoImp implements BranchRepo { token: appState.getUser.data!.accessToken, queryParameters: postParams, ); - List nearBranches = List.generate(adsGenericModel.data.length, (index) => BranchDetailModel.fromJson(adsGenericModel.data[index])); - return nearBranches; + List favProviders = List.generate(adsGenericModel.data.length, (index) => ProviderProfileModel.fromJson(adsGenericModel.data[index])); + return favProviders; } } diff --git a/lib/repositories/items_repo.dart b/lib/repositories/items_repo.dart index 9688c75..3387ff2 100644 --- a/lib/repositories/items_repo.dart +++ b/lib/repositories/items_repo.dart @@ -4,24 +4,24 @@ import 'package:mc_common_app/api/api_client.dart'; import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/config/dependency_injection.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; +import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; import 'package:mc_common_app/models/services_models/item_model.dart'; abstract class ItemsRepo { - Future createServiceItems(Map map); + Future createServiceItems(Map map); Future getServiceItems(int serviceId); - Future updateServiceItem(Map map); + Future updateServiceItem(Map map); } class ItemsRepoImp implements ItemsRepo { @override - Future createServiceItems(Map map) async { + Future createServiceItems(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; debugPrint(t); - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createItems, map, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createItems, map, token: t); } @override @@ -37,10 +37,10 @@ class ItemsRepoImp implements ItemsRepo { } @override - Future updateServiceItem(Map map) async { + Future updateServiceItem(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; debugPrint(t); - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateServiceItem, map, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateServiceItem, map, token: t); } } diff --git a/lib/repositories/request_repo.dart b/lib/repositories/request_repo.dart index 36f4f08..18fcd7b 100644 --- a/lib/repositories/request_repo.dart +++ b/lib/repositories/request_repo.dart @@ -69,6 +69,7 @@ class RequestRepoImp implements RequestRepo { Future> getServiceRequestsForProviders({required int serviceProviderID}) async { final parameters = { "ServiceProviderId": serviceProviderID.toString(), + "RequestTypeId": "2", // Only to get the Service Request }; GenericRespModel genericRespModel = await apiClient.getJsonForObject( (json) => GenericRespModel.fromJson(json), diff --git a/lib/repositories/schedule_repo.dart b/lib/repositories/schedule_repo.dart index 09be713..9bd78e9 100644 --- a/lib/repositories/schedule_repo.dart +++ b/lib/repositories/schedule_repo.dart @@ -1,5 +1,5 @@ import 'package:mc_common_app/models/appointments_models/schedule_model.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; +import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; import 'package:mc_common_app/models/provider_branches_models/profile/services.dart'; import 'package:mc_common_app/api/api_client.dart'; import 'package:mc_common_app/classes/app_state.dart'; @@ -9,17 +9,17 @@ import 'package:mc_common_app/config/dependency_injection.dart'; abstract class ScheduleRepo { Future getAllServices(String branchId); - Future createSchedule(Map map); + Future createSchedule(Map map); - Future addServicesInSchedule(Map map); + Future addServicesInSchedule(Map map); - Future updateSchedule(Map map); + Future updateSchedule(Map map); Future getSchedules(String branchId); - Future updateServicesInSchedule(Map map); + Future updateServicesInSchedule(Map map); - Future setScheduleInActive(int scheduleId, int branchId); + Future setScheduleInActive(int scheduleId, int branchId); } class ScheduleRepoImp implements ScheduleRepo { @@ -31,15 +31,15 @@ class ScheduleRepoImp implements ScheduleRepo { } @override - Future createSchedule(Map map) async { + Future createSchedule(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createSchedule, map, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createSchedule, map, token: t); } @override - Future addServicesInSchedule(Map map) async { + Future addServicesInSchedule(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.createGroup, map, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.createGroup, map, token: t); } @override @@ -50,25 +50,25 @@ class ScheduleRepoImp implements ScheduleRepo { } @override - Future setScheduleInActive(int scheduleId, int branchId) async { + Future setScheduleInActive(int scheduleId, int branchId) async { Map map = { "id": scheduleId, "serviceProviderBranchID": branchId, "isActive": false, }; String t = AppState().getUser.data!.accessToken ?? ""; - return injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.setScheduleInactive, token: t, map); + return injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.setScheduleInactive, token: t, map); } @override - Future updateSchedule(Map map) async { + Future updateSchedule(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateSchedule, map, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateSchedule, map, token: t); } @override - Future updateServicesInSchedule(Map map) async { + Future updateServicesInSchedule(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.updateGroup, map, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.updateGroup, map, token: t); } } diff --git a/lib/repositories/subscription_repo.dart b/lib/repositories/subscription_repo.dart index ad2e154..37b5524 100644 --- a/lib/repositories/subscription_repo.dart +++ b/lib/repositories/subscription_repo.dart @@ -3,7 +3,6 @@ import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/config/dependency_injection.dart'; import 'package:mc_common_app/models/general_models/generic_resp_model.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/subscriptions_models/branch_user_selection_model.dart'; import 'package:mc_common_app/models/subscriptions_models/provider_subscription_model.dart'; @@ -19,11 +18,11 @@ abstract class SubscriptionRepo { Future getSubscriptionBySP(String? serviceProviderID, bool isRenew); - Future calculationUpgradePrice(String? serviceProviderID, String? newSubscription); + Future calculationUpgradePrice(String? serviceProviderID, String? newSubscription); - Future payForProviderSubscription(Map map); + Future payForProviderSubscription(Map map); - Future> getSPBranchUser_Get(Map map); + Future> getSPBranchUserGet(Map map); } class SubscriptionRepoImp extends SubscriptionRepo { @@ -63,7 +62,7 @@ class SubscriptionRepoImp extends SubscriptionRepo { } @override - Future calculationUpgradePrice(String? serviceProviderID, String? newSubscription) async { + Future calculationUpgradePrice(String? serviceProviderID, String? newSubscription) async { String t = AppState().getUser.data!.accessToken ?? ""; Map queryParameters = {}; if (serviceProviderID != null) { @@ -74,7 +73,7 @@ class SubscriptionRepoImp extends SubscriptionRepo { } return await injector.get().getJsonForObject( - (json) => MResponse.fromJson(json), + (json) => GenericRespModel.fromJson(json), ApiConsts.calculationUpgradePrice, token: t, queryParameters: queryParameters, @@ -82,11 +81,11 @@ class SubscriptionRepoImp extends SubscriptionRepo { } @override - Future payForProviderSubscription(Map map) async { + Future payForProviderSubscription(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; return await injector.get().postJsonForObject( - (json) => MResponse.fromJson(json), + (json) => GenericRespModel.fromJson(json), ApiConsts.payFortOrderProviderSubscriptionCreate, map, token: t, @@ -94,7 +93,7 @@ class SubscriptionRepoImp extends SubscriptionRepo { } @override - Future> getSPBranchUser_Get(Map map) async { + Future> getSPBranchUserGet(Map map) async { String t = AppState().getUser.data!.accessToken ?? ""; GenericRespModel genericRespModel = await injector.get().getJsonForObject( diff --git a/lib/repositories/user_repo.dart b/lib/repositories/user_repo.dart index dc499d0..5f5bd31 100644 --- a/lib/repositories/user_repo.dart +++ b/lib/repositories/user_repo.dart @@ -7,7 +7,7 @@ import 'package:mc_common_app/api/api_client.dart'; import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/classes/consts.dart'; import 'package:mc_common_app/config/dependency_injection.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; +import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; import 'package:mc_common_app/models/user_models/basic_otp.dart'; import 'package:mc_common_app/models/user_models/change_email.dart'; import 'package:mc_common_app/models/user_models/change_mobile.dart'; @@ -53,7 +53,7 @@ abstract class UserRepo { Future forgetPassword(String userToken, String newPassword); - Future changePassword(String currentPassword, String newPassword); + Future changePassword(String currentPassword, String newPassword); Future changeMobileNoOTPRequest(countryID, String mobileNo, String password); @@ -65,7 +65,7 @@ abstract class UserRepo { Future emailVerify(String email, String userID); - Future emailVerifyOTPVerify(String userToken, String userOTP); + Future emailVerifyOTPVerify(String userToken, String userOTP); Future updateUserImage(String image); @@ -211,7 +211,7 @@ class UserRepoImp implements UserRepo { } @override - Future changePassword(String currentPassword, String newPassword) async { + Future changePassword(String currentPassword, String newPassword) async { var postParams = { "currentPassword": currentPassword, "newPassword": newPassword, @@ -220,7 +220,7 @@ class UserRepoImp implements UserRepo { String t = AppState().getUser.data!.accessToken ?? ""; debugPrint("token $t"); - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.ChangePassword, postParams, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.ChangePassword, postParams, token: t); } @override @@ -268,11 +268,11 @@ class UserRepoImp implements UserRepo { } @override - Future emailVerifyOTPVerify(String userToken, String userOTP) async { + Future emailVerifyOTPVerify(String userToken, String userOTP) async { var postParams = {"userToken": userToken, "userOTP": userOTP}; String t = AppState().getUser.data!.accessToken ?? ""; - return await injector.get().postJsonForObject((json) => MResponse.fromJson(json), ApiConsts.EmailVerifyOTPVerify, postParams, token: t); + return await injector.get().postJsonForObject((json) => GenericRespModel.fromJson(json), ApiConsts.EmailVerifyOTPVerify, postParams, token: t); } @override diff --git a/lib/services/common_services.dart b/lib/services/common_services.dart index e75d97f..56daf74 100644 --- a/lib/services/common_services.dart +++ b/lib/services/common_services.dart @@ -2,7 +2,9 @@ import 'dart:io'; import 'package:file_picker/file_picker.dart'; import 'package:flutter/material.dart'; +import 'package:geolocator/geolocator.dart'; import 'package:image_picker/image_picker.dart'; +import 'package:mc_common_app/main.dart'; import 'package:mc_common_app/utils/app_permission_handler.dart'; abstract class CommonAppServices { @@ -12,8 +14,14 @@ abstract class CommonAppServices { Future?> pickMultipleFiles(BuildContext context); - Future pickFile(BuildContext context, - {required FileType fileType, List? allowedExtensions}); + Future pickFile(BuildContext context, {required FileType fileType, List? allowedExtensions}); + + double getDistanceBetween({ + required double curLatitude, + required double curLongitude, + required double destLatitude, + required double destLongitude, + }); } class CommonServicesImp implements CommonAppServices { @@ -66,16 +74,12 @@ class CommonServicesImp implements CommonAppServices { } @override - Future pickFile(BuildContext context, - {required FileType fileType, List? allowedExtensions}) async { + Future pickFile(BuildContext context, {required FileType fileType, List? allowedExtensions}) async { FilePickerResult? result; final status = await AppPermissions.checkStoragePermissions(context); if (status) { - result = await FilePicker.platform.pickFiles( - allowMultiple: true, - type: fileType, - allowedExtensions: allowedExtensions); + result = await FilePicker.platform.pickFiles(allowMultiple: true, type: fileType, allowedExtensions: allowedExtensions); } List pickedFiles = []; @@ -86,6 +90,23 @@ class CommonServicesImp implements CommonAppServices { } } } - return pickedFiles.length > 0 ? pickedFiles.first : null; + return pickedFiles.isNotEmpty ? pickedFiles.first : null; + } + + @override + double getDistanceBetween({required double curLatitude, required double curLongitude, required double destLatitude, required double destLongitude}) { + try { + double distance = Geolocator.distanceBetween( + curLatitude, + curLongitude, + destLatitude, + destLongitude, + ); + + return distance ?? 0.0; + } catch (e) { + logger.e(e.toString()); + return 0.0; + } } } diff --git a/lib/utils/utils.dart b/lib/utils/utils.dart index 96d1afe..5daff24 100644 --- a/lib/utils/utils.dart +++ b/lib/utils/utils.dart @@ -22,8 +22,7 @@ class Utils { static bool get isLoading => _isLoadingVisible; static void showToast(String message) { - Fluttertoast.showToast( - msg: message, toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 2, backgroundColor: Colors.black54, textColor: Colors.white, fontSize: 16.0); + Fluttertoast.showToast(msg: message, toastLength: Toast.LENGTH_SHORT, gravity: ToastGravity.BOTTOM, timeInSecForIosWeb: 2, backgroundColor: Colors.black54, textColor: Colors.white, fontSize: 16.0); } static Future openNumberViaCaller({required String phoneNumber}) async { @@ -250,8 +249,52 @@ class Utils { } } - static statusContainerChip( - {required String text, EdgeInsetsGeometry padding = const EdgeInsets.symmetric(vertical: 3, horizontal: 6), Color chipColor = MyColors.greenColor, Color textColor = MyColors.white}) { + static Color getChipColorByBranchStatus(BranchStatusEnum branchStatusEnum) { + switch (branchStatusEnum) { + case BranchStatusEnum.pending: + return MyColors.adPendingStatusColor; + + case BranchStatusEnum.review: + return MyColors.adPendingStatusColor; + + case BranchStatusEnum.rejected: + return MyColors.adCancelledStatusColor; + + case BranchStatusEnum.deactivated: + return MyColors.adCancelledStatusColor; + + case BranchStatusEnum.blocked: + return MyColors.adPendingStatusColor; + + case BranchStatusEnum.approvedOrActive: + return MyColors.greenColor; + } + } + + + static String getChipStatusTextByBranchStatus(BranchStatusEnum branchStatusEnum) { + switch (branchStatusEnum) { + case BranchStatusEnum.pending: + return "Pending Approval"; + + case BranchStatusEnum.review: + return "In Review"; + + case BranchStatusEnum.rejected: + return "Rejected"; + + case BranchStatusEnum.deactivated: + return "Deactivated"; + + case BranchStatusEnum.blocked: + return "Blocked"; + + case BranchStatusEnum.approvedOrActive: + return "Active"; + } + } + + static statusContainerChip({required String text, EdgeInsetsGeometry padding = const EdgeInsets.symmetric(vertical: 3, horizontal: 6), Color chipColor = MyColors.greenColor, Color textColor = MyColors.white}) { return Container( decoration: BoxDecoration( color: chipColor, diff --git a/lib/view_models/appointments_view_model.dart b/lib/view_models/appointments_view_model.dart index 2145351..04791d4 100644 --- a/lib/view_models/appointments_view_model.dart +++ b/lib/view_models/appointments_view_model.dart @@ -13,7 +13,6 @@ import 'package:mc_common_app/models/appointments_models/appointment_slots.dart' import 'package:mc_common_app/models/appointments_models/service_schedule_model.dart'; import 'package:mc_common_app/models/general_models/enums_model.dart'; import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; import 'package:mc_common_app/models/general_models/widgets_models.dart'; import 'package:mc_common_app/models/provider_branches_models/branch_detail_model.dart'; import 'package:mc_common_app/models/provider_branches_models/branch_review_model.dart'; @@ -372,7 +371,7 @@ class AppointmentsVM extends BaseVM { Future getAppointmentSlotsInfo({required Map map, required BuildContext context, bool isNeedToRebuild = false}) async { if (isNeedToRebuild) setState(ViewState.busy); try { - MResponse genericRespModel = await appointmentRepo.getAppointmentSlots(map); + GenericRespModel genericRespModel = await appointmentRepo.getAppointmentSlots(map); if (genericRespModel.messageStatus == 1) { appointmentSlots = AppointmentSlots.fromJson(genericRespModel.data); } else { @@ -395,7 +394,7 @@ class AppointmentsVM extends BaseVM { updateAppointmentStatus(Map map, {bool isNeedToRebuild = false}) async { if (isNeedToRebuild) setState(ViewState.busy); try { - MResponse genericRespModel = await appointmentRepo.updateAppointmentStatus(map); + GenericRespModel genericRespModel = await appointmentRepo.updateAppointmentStatus(map); if (genericRespModel.messageStatus == 1) { Utils.showToast(LocaleKeys.appointmentStatusUpdated.tr()); @@ -410,7 +409,7 @@ class AppointmentsVM extends BaseVM { updateAppointmentPaymentStatus(Map map, {bool isNeedToRebuild = false}) async { if (isNeedToRebuild) setState(ViewState.busy); try { - MResponse genericRespModel = await appointmentRepo.updateAppointmentPaymentStatus(map); + GenericRespModel genericRespModel = await appointmentRepo.updateAppointmentPaymentStatus(map); if (genericRespModel.messageStatus == 1) { Utils.showToast(LocaleKeys.paymentStatusUpdated.tr()); @@ -422,9 +421,9 @@ class AppointmentsVM extends BaseVM { } } - Future createMergeAppointment(Map map, {bool isNeedToRebuild = false}) async { + Future createMergeAppointment(Map map, {bool isNeedToRebuild = false}) async { if (isNeedToRebuild) setState(ViewState.busy); - MResponse genericRespModel = await appointmentRepo.createMergeAppointment(map); + GenericRespModel genericRespModel = await appointmentRepo.createMergeAppointment(map); return genericRespModel; } @@ -848,7 +847,7 @@ class AppointmentsVM extends BaseVM { notifyListeners(); } - getBranchServices({required int categoryId}) async { + Future getBranchServices({required int categoryId}) async { branchSelectedServiceId = SelectionModel(selectedOption: "", selectedId: -1, errorValue: ""); isHomeTapped = false; pickedHomeLocation = ""; @@ -1453,6 +1452,21 @@ class AppointmentsVM extends BaseVM { } } + List myFavProvidersList = []; + + Future getMyFavoriteProviders() async { + myFavProvidersList.clear(); + setState(ViewState.busy); + try { + myFavProvidersList = await branchRepo.getMyFavoriteProviders(); + setState(ViewState.idle); + } catch (e, s) { + logger.e(s); + setState(ViewState.idle); + Utils.showToast(e.toString()); + } + } + List currentBranchReviews = []; bool isReadMoreEnabled = false; diff --git a/lib/view_models/requests_view_model.dart b/lib/view_models/requests_view_model.dart index e1111ae..94e0479 100644 --- a/lib/view_models/requests_view_model.dart +++ b/lib/view_models/requests_view_model.dart @@ -379,6 +379,25 @@ class RequestsVM extends BaseVM { } } + String itemManufacturer = ""; + + void updateItemManufacturer(String value) { + itemManufacturer = value; + } + + String serviceItem = ""; + + void updateServiceItem(String value) { + serviceItem = value; + } + + String serviceItemCreatedOn = ""; + + void updateServiceItemCreatedOn(String value) { + serviceItemCreatedOn = value; + notifyListeners(); + } + String offerDescription = ""; void updateOfferDescription(String value) { @@ -415,7 +434,9 @@ class RequestsVM extends BaseVM { offerPrice = ""; offerDescription = ""; offerDescriptionError = ""; - offerDescription = ""; + serviceItem = ""; + serviceItemCreatedOn = ""; + itemManufacturer = ""; notifyListeners(); } diff --git a/lib/view_models/service_view_model.dart b/lib/view_models/service_view_model.dart index 07f928c..d9f9212 100644 --- a/lib/view_models/service_view_model.dart +++ b/lib/view_models/service_view_model.dart @@ -1,246 +1,11 @@ -// 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 countryDropList = []; -// List 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 updateDocument(List? 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 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 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 categoryDropList = []; -// List 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 createService(List> map) async { -// return await branchRepo.createService(map); -// } -// -// Future updateServices(List> map) async { -// return await branchRepo.updateService(map); -// } -// -// updateSelectedBranchType(int status) { -// selectedBranchStatus = status; -// notifyListeners(); -// } -// -// List? 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.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 copiedItems) { -// matchedServices![index].serviceItems = copiedItems; -// notifyListeners(); -// } -// -// Future duplicateItems(Map map) async { -// return await branchRepo.duplicateItems(map); -// } -// } - import 'dart:io'; +import 'package:flutter/material.dart'; +import 'package:mc_common_app/classes/app_state.dart'; import 'package:mc_common_app/generated/locale_keys.g.dart'; +import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; 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'; @@ -255,7 +20,9 @@ import 'package:mc_common_app/repositories/common_repo.dart'; import 'package:mc_common_app/services/common_services.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/navigator.dart'; import 'package:mc_common_app/utils/utils.dart'; +import 'package:mc_common_app/view_models/ad_view_model.dart'; import 'package:mc_common_app/view_models/base_view_model.dart'; import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -291,12 +58,49 @@ class ServiceVM extends BaseVM { String branchName = ""; String branchDescription = ""; + double getDistanceFromMe({ + required String destLatitude, + required String destLongitude, + }) { + double distance = commonServices.getDistanceBetween( + curLatitude: AppState().currentLocation.latitude, + curLongitude: AppState().currentLocation.longitude, + destLatitude: double.parse(destLatitude), + destLongitude: double.parse(destLongitude), + ); + + return distance; + } + Future getServiceProviderDocument(int providerId) async { setState(ViewState.busy); document = await branchRepo.getServiceProviderDocument(providerId); setState(ViewState.idle); } + List pickedBranchImages = []; + String branchImageError = ""; + + void removeImageFromList(String filePath) { + int index = pickedBranchImages.indexWhere((element) => element.filePath == filePath); + if (index == -1) { + return; + } + pickedBranchImages.removeAt(index); + notifyListeners(); + } + + void pickMultipleImages() async { + List imageModels = []; + List images = await commonServices.pickMultipleImages(); + for (var element in images) { + imageModels.add(ImageModel(filePath: element.path, isFromNetwork: false)); + } + pickedBranchImages.addAll(imageModels); + if (pickedBranchImages.isNotEmpty) branchImageError = ""; + notifyListeners(); + } + Future selectFile(BuildContext context, int index) async { final status = await AppPermissions.checkStoragePermissions(context); if (status) { @@ -305,23 +109,6 @@ class ServiceVM extends BaseVM { 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); @@ -339,7 +126,7 @@ class ServiceVM extends BaseVM { } } - Future updateDocument(List? data) async { + Future updateDocument(List? data) async { return await branchRepo.serviceProviderDocumentsUpdate(data); } @@ -362,9 +149,7 @@ class ServiceVM extends BaseVM { countryId = element.id ?? -1; countryValue = DropValue( element.id ?? 0, - countryCode == "SA" - ? (element.countryNameN ?? "") - : (element.countryName ?? ""), + countryCode == "SA" ? (element.countryNameN ?? "") : (element.countryName ?? ""), element.countryCode ?? "", ); } @@ -372,9 +157,7 @@ class ServiceVM extends BaseVM { countryDropList.add( DropValue( element.id ?? 0, - countryCode == "SA" - ? (element.countryNameN ?? "") - : (element.countryName ?? ""), + countryCode == "SA" ? (element.countryNameN ?? "") : (element.countryName ?? ""), element.countryCode ?? "", ), ); @@ -404,43 +187,34 @@ class ServiceVM extends BaseVM { cityId = branchData.cityId!; cityValue = DropValue( element.id ?? 0, - countryCode == "SA" - ? (element.cityNameN ?? "") - : (element.cityName ?? ""), - element.id.toString() ?? "", + countryCode == "SA" ? (element.cityNameN ?? "") : (element.cityName ?? ""), + (element.id ?? "").toString(), ); } } citiesDropList.add( DropValue( element.id ?? 0, - countryCode == "SA" - ? (element.cityNameN ?? "") - : (element.cityName ?? ""), - element.id.toString() ?? "", + countryCode == "SA" ? (element.cityNameN ?? "") : (element.cityName ?? ""), + (element.id ?? "").toString(), ), ); }); setState(ViewState.idle); } - Future 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 updateBranch(int id, - String branchName, - String branchDescription, - String cityId, - String address, - String latitude, - String longitude, { - bool isNeedToDelete = true, - }) async { + 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 ?? 0, + id, branchName, branchDescription, cityId.toString(), @@ -485,10 +259,10 @@ class ServiceVM extends BaseVM { DropValue( element.id ?? 0, ((element.categoryName!.isEmpty - ? "N/A" - : countryCode == "SA" - ? element.categoryNameN - : element.categoryName) ?? + ? "N/A" + : countryCode == "SA" + ? element.categoryNameN + : element.categoryName) ?? "N/A"), "", ), @@ -500,8 +274,7 @@ class ServiceVM extends BaseVM { Future fetchServicesByCategoryId(int categoryId) async { servicesDropList = []; setState(ViewState.busy); - services = await branchRepo.fetchServicesByCategoryId( - serviceCategoryId: categoryId); // to get all the services + services = await branchRepo.fetchServicesByCategoryId(serviceCategoryId: categoryId); // to get all the services for (var element in services!.data!) { servicesDropList.add( DropValue( @@ -532,11 +305,11 @@ class ServiceVM extends BaseVM { setState(ViewState.idle); } - Future createService(List> map) async { + Future createService(List> map) async { return await branchRepo.createService(map); } - Future updateServices(List> map) async { + Future updateServices(List> map) async { return await branchRepo.updateService(map); } @@ -550,13 +323,11 @@ class ServiceVM extends BaseVM { Future getAllMatchedServices(int oldBranchId, int newBranchId, int categoryId) async { matchedServices = null; - final MResponse response = await branchRepo.getMatchedServices( - oldBranchId, newBranchId, categoryId); + final GenericRespModel response = await branchRepo.getMatchedServices(oldBranchId, newBranchId, categoryId); matchedServices = []; if (response.messageStatus == 1) { - matchedServices = List.from( - response.data.map((x) => ServiceModel.fromJson(x))); + matchedServices = List.from(response.data.map((x) => ServiceModel.fromJson(x))); } notifyListeners(); } @@ -584,7 +355,7 @@ class ServiceVM extends BaseVM { notifyListeners(); } - Future duplicateItems(Map map) async { + Future duplicateItems(Map map) async { return await branchRepo.duplicateItems(map); } @@ -594,38 +365,89 @@ class ServiceVM extends BaseVM { getAllProviderDealers(Map map) async { setState(ViewState.busy); - MResponse response = await branchRepo.getAllProviderDealers(map); + GenericRespModel response = await branchRepo.getAllProviderDealers(map); if (response.messageStatus == 1) { allProviderDealersList = []; - allProviderDealersList = List.from( - response.data.map((x) => BranchUser.fromJson(x))); + allProviderDealersList = List.from(response.data.map((x) => BranchUser.fromJson(x))); } setState(ViewState.idle); } Future getBranchUsers(Map map) async { setState(ViewState.busy); - MResponse response = await branchRepo.getBranchUsers(map); + GenericRespModel response = await branchRepo.getBranchUsers(map); if (response.messageStatus == 1) { branchUserList = []; - branchUserList = List.from( - response.data.map((x) => BranchUser.fromJson(x))); + branchUserList = List.from(response.data.map((x) => BranchUser.fromJson(x))); } setState(ViewState.idle); } - Future assignDealerToBranch(Map map) async { - MResponse response = await branchRepo.assignDealerToBranch(map); + Future assignDealerToBranch(Map map) async { + GenericRespModel response = await branchRepo.assignDealerToBranch(map); return response; } - Future removeDealerFromBranch(Map map) async { - MResponse response = await branchRepo.removeDealerFromBranch(map); + Future removeDealerFromBranch(Map map) async { + GenericRespModel response = await branchRepo.removeDealerFromBranch(map); return response; } - Future addNewServiceInAppointment(Map map) async { - MResponse response = await branchRepo.addNewServicesInAppointment(map); + Future addNewServiceInAppointment(Map map) async { + GenericRespModel response = await branchRepo.addNewServicesInAppointment(map); 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(); + } else { + Utils.showToast(res.message ?? ""); + } + } + + Future onUpdateBranchPressed({ + required BuildContext context, + required int branchID, + required String branchName, + required String branchDesc, + required int cityID, + required String address, + required double 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 ?? ""); + } + } } diff --git a/lib/view_models/subscriptions_view_model.dart b/lib/view_models/subscriptions_view_model.dart index f0ff88f..29f48ae 100644 --- a/lib/view_models/subscriptions_view_model.dart +++ b/lib/view_models/subscriptions_view_model.dart @@ -1,7 +1,7 @@ import 'dart:convert'; import 'package:mc_common_app/classes/app_state.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; +import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; import 'package:mc_common_app/models/subscriptions_models/branch_user_selection_model.dart'; import 'package:mc_common_app/models/subscriptions_models/provider_subscription_model.dart'; import 'package:mc_common_app/models/subscriptions_models/subscription_model.dart'; @@ -17,7 +17,7 @@ class SubscriptionsVM extends BaseVM { //All Subscriptions int selectedIndex = 0; - late DropValue selectedMothlyTab; + late DropValue selectedMonthlyTab; List monthlyTabs = []; late SubscriptionModel allSubscriptions; List mySubscriptionsBySp = []; @@ -40,7 +40,7 @@ class SubscriptionsVM extends BaseVM { } monthlyTabs.sort((a, b) => a.value.compareTo(b.value)); monthlyTabs.first.isEnabled = true; - selectedMothlyTab = monthlyTabs.first; + selectedMonthlyTab = monthlyTabs.first; filterSubscriptions(); setState(ViewState.idle); } else { @@ -62,7 +62,7 @@ class SubscriptionsVM extends BaseVM { } monthlyTabs.sort((a, b) => a.value.compareTo(b.value)); monthlyTabs.first.isEnabled = true; - selectedMothlyTab = monthlyTabs.first; + selectedMonthlyTab = monthlyTabs.first; filterSubscriptions(); setState(ViewState.idle); @@ -75,16 +75,16 @@ class SubscriptionsVM extends BaseVM { calculationUpgradePrice(String? serviceProviderID, String? newSubscription) async { setState(ViewState.busy); - MResponse mResponse = await subscriptionRepo.calculationUpgradePrice(serviceProviderID, newSubscription); - if (mResponse.messageStatus == 1) { + GenericRespModel genericRespModel = await subscriptionRepo.calculationUpgradePrice(serviceProviderID, newSubscription); + if (genericRespModel.messageStatus == 1) { setState(ViewState.idle); - newPrice = mResponse.data.toString(); + newPrice = genericRespModel.data.toString(); } else { setState(ViewState.error); } } - Future payForSubscription(int subscriptionId, bool isStartNow, bool isReview, String amount, {bool isDegrade = false, List? listOfBranches, List? listOfUsers}) async { + Future payForSubscription(int subscriptionId, bool isStartNow, bool isReview, String amount, {bool isDegrade = false, List? listOfBranches, List? listOfUsers}) async { Map map; if (isDegrade) { map = { @@ -111,24 +111,19 @@ class SubscriptionsVM extends BaseVM { // "listOfUsers": [] }; } - MResponse mResponse = await subscriptionRepo.payForProviderSubscription(map); - return mResponse; + GenericRespModel genericRespModel = await subscriptionRepo.payForProviderSubscription(map); + return genericRespModel; } - Future createSubscriptionOrder(int subscriptionId, bool isStartNow, bool isRenew, {bool isDegrade = false, List? listOfBranches, List? listOfUsers}) async { - Map map = { - "providerID": AppState().getUser.data?.userInfo?.providerId.toString() ?? "", - "subscriptionID": subscriptionId.toString(), - "isStartNow": isStartNow.toString(), - "isRenew": isRenew.toString() - }; - MResponse mResponse = await subscriptionRepo.payForProviderSubscription(map); - return mResponse; + Future createSubscriptionOrder(int subscriptionId, bool isStartNow, bool isRenew, {bool isDegrade = false, List? listOfBranches, List? listOfUsers}) async { + Map map = {"providerID": AppState().getUser.data?.userInfo?.providerId.toString() ?? "", "subscriptionID": subscriptionId.toString(), "isStartNow": isStartNow.toString(), "isRenew": isRenew.toString()}; + GenericRespModel genericRespModel = await subscriptionRepo.payForProviderSubscription(map); + return genericRespModel; } List? branchSelectionList; - getSPBranchUser_Get() async { + getSPBranchUserGet() async { branchSelectionList = null; Map map = { // "id": subscription.id.toString(), @@ -137,7 +132,7 @@ class SubscriptionsVM extends BaseVM { // "listOfBranches": [], // "listOfUsers": [] }; - branchSelectionList = await subscriptionRepo.getSPBranchUser_Get(map); + branchSelectionList = await subscriptionRepo.getSPBranchUserGet(map); if (branchSelectionList!.isNotEmpty) { branchSelectionList!.first.isOpend = true; } @@ -148,15 +143,15 @@ class SubscriptionsVM extends BaseVM { final int months = days ~/ 30; final int remainingDays = days % 30; - String _result = months > 0 ? '$months Month${months > 1 ? 's' : ''}${remainingDays > 0 ? ' & ' : ''}' : ''; - _result += remainingDays > 0 ? '$remainingDays Day${remainingDays > 1 ? 's' : ''}' : ''; - return _result; + String result = months > 0 ? '$months Month${months > 1 ? 's' : ''}${remainingDays > 0 ? ' & ' : ''}' : ''; + result += remainingDays > 0 ? '$remainingDays Day${remainingDays > 1 ? 's' : ''}' : ''; + return result; } filterSubscriptions() { tempSubscriptions.clear(); for (var element in allSubscriptions.data!) { - if (selectedMothlyTab.id == element.durationDays) { + if (selectedMonthlyTab.id == element.durationDays) { tempSubscriptions.add(element); } if (element.id == AppState().getproviderSubscription.first.subscriptionID) { diff --git a/lib/view_models/user_view_model.dart b/lib/view_models/user_view_model.dart index 264cfb1..3605bf0 100644 --- a/lib/view_models/user_view_model.dart +++ b/lib/view_models/user_view_model.dart @@ -11,7 +11,8 @@ import 'package:mc_common_app/config/routes.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/main.dart'; -import 'package:mc_common_app/models/general_models/m_response.dart'; +import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; +import 'package:mc_common_app/models/general_models/generic_resp_model.dart'; import 'package:mc_common_app/models/user_models/basic_otp.dart'; import 'package:mc_common_app/models/user_models/change_email.dart'; import 'package:mc_common_app/models/user_models/change_mobile.dart'; @@ -140,7 +141,7 @@ class UserVM extends BaseVM { Future changeUserPassword(BuildContext context, String newPassword, String currentPassword) async { if (Utils.passwordValidateStructure(newPassword)) { Utils.showLoading(context); - MResponse res = await userRepo.changePassword(currentPassword, newPassword); + GenericRespModel res = await userRepo.changePassword(currentPassword, newPassword); Utils.hideLoading(context); if (res.messageStatus == 1) { Utils.showToast(LocaleKeys.passwordIsUpdated.tr()); @@ -270,7 +271,7 @@ class UserVM extends BaseVM { onClick: (String code) async { pop(context); Utils.showLoading(context); - MResponse otpCompare = await userRepo.emailVerifyOTPVerify(otpRequest.data!.userToken ?? "", code); + GenericRespModel otpCompare = await userRepo.emailVerifyOTPVerify(otpRequest.data!.userToken ?? "", code); Utils.hideLoading(context); if (otpCompare.messageStatus == 1) { AppState().getUser.data!.userInfo!.isEmailVerified = true; diff --git a/lib/views/advertisement/ads_detail_view.dart b/lib/views/advertisement/ads_detail_view.dart index 4313fcd..115de7f 100644 --- a/lib/views/advertisement/ads_detail_view.dart +++ b/lib/views/advertisement/ads_detail_view.dart @@ -118,7 +118,7 @@ class _AdsDetailViewState extends State { mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ - AdImagesCorouselWidget(vehicleImages: widget.adDetails.vehicle!.image!), + ImagesCorouselWidget(imagesList: widget.adDetails.vehicle!.image!), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ diff --git a/lib/views/advertisement/components/ads_images_corousel_widget.dart b/lib/views/advertisement/components/ads_images_corousel_widget.dart index 61f5ee0..80a4b56 100644 --- a/lib/views/advertisement/components/ads_images_corousel_widget.dart +++ b/lib/views/advertisement/components/ads_images_corousel_widget.dart @@ -2,17 +2,18 @@ import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/material.dart'; import 'package:mc_common_app/models/advertisment_models/ad_details_model.dart'; import 'package:mc_common_app/theme/colors.dart'; +import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; -class AdImagesCorouselWidget extends StatefulWidget { - final List vehicleImages; +class ImagesCorouselWidget extends StatefulWidget { + final List imagesList; - const AdImagesCorouselWidget({super.key, required this.vehicleImages}); + const ImagesCorouselWidget({super.key, required this.imagesList}); @override State createState() => _CarouselWithIndicatorState(); } -class _CarouselWithIndicatorState extends State { +class _CarouselWithIndicatorState extends State { int _current = 0; final CarouselController _controller = CarouselController(); @@ -20,21 +21,14 @@ class _CarouselWithIndicatorState extends State { Widget build(BuildContext context) { return Column(children: [ CarouselSlider( - items: widget.vehicleImages + items: widget.imagesList .map((item) => Container( margin: const EdgeInsets.all(5.0), child: ClipRRect( borderRadius: const BorderRadius.all(Radius.circular(5.0)), - child: Image.network( - item.imageUrl!, - fit: BoxFit.cover, - errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { - return const SizedBox( - width: 80, - height: 80, - child: Icon(Icons.error_outline), - ); - }, + child: item.imageUrl.buildNetworkImage( + height: 80, + width: 80, ), ), )) @@ -52,7 +46,7 @@ class _CarouselWithIndicatorState extends State { ), Row( mainAxisAlignment: MainAxisAlignment.center, - children: widget.vehicleImages.asMap().entries.map((entry) { + children: widget.imagesList.asMap().entries.map((entry) { return GestureDetector( onTap: () => _controller.animateToPage(entry.key), child: Container( diff --git a/lib/views/appointments/pick_items_view.dart b/lib/views/appointments/pick_items_view.dart index caffb24..0dc143d 100644 --- a/lib/views/appointments/pick_items_view.dart +++ b/lib/views/appointments/pick_items_view.dart @@ -6,7 +6,7 @@ import 'package:mc_common_app/generated/locale_keys.g.dart'; import 'package:mc_common_app/theme/colors.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/common_widgets/provider_details_card.dart'; +import 'package:mc_common_app/widgets/common_widgets/branch_details_card.dart'; import 'package:mc_common_app/widgets/common_widgets/time_slots.dart'; import 'package:mc_common_app/widgets/dropdown/dropdow_field.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; @@ -40,7 +40,7 @@ class _BookProviderAppViewState extends State { Expanded( child: ListView( children: [ - ProviderDetailsCard( + BranchDetailCard( onCardTapped: () {}, providerImageUrl: MyAssets.bnCar, providerLocation: "3km", diff --git a/lib/views/requests/create_request_page.dart b/lib/views/requests/create_request_page.dart index 16c209c..2c3f9f7 100644 --- a/lib/views/requests/create_request_page.dart +++ b/lib/views/requests/create_request_page.dart @@ -33,9 +33,7 @@ class CreateRequestPage extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - LocaleKeys.vehicleDetails - .tr() - .toText(fontSize: 18, isBold: true), + LocaleKeys.vehicleDetails.tr().toText(fontSize: 18, isBold: true), 8.height, if (requestsVM.isFetchingRequestType) ...[ const Center( @@ -45,24 +43,12 @@ class CreateRequestPage extends StatelessWidget { Builder(builder: (context) { List requestTypeDrop = []; for (var element in requestsVM.myRequestsTypeEnum) { - requestTypeDrop.add(DropValue( - element.enumValue.toInt() ?? 0, - element.enumValueStr ?? "", - "")); + requestTypeDrop.add(DropValue(element.enumValue.toInt() ?? 0, element.enumValueStr ?? "", "")); } return DropdownField( - (DropValue value) => requestsVM - .updateSelectionRequestTypeId(SelectionModel( - selectedId: value.id, - selectedOption: value.value)), + (DropValue value) => requestsVM.updateSelectionRequestTypeId(SelectionModel(selectedId: value.id, selectedOption: value.value)), list: requestTypeDrop, - dropdownValue: - requestsVM.requestTypeId.selectedId != -1 - ? DropValue( - requestsVM.requestTypeId.selectedId, - requestsVM.requestTypeId.selectedOption, - "") - : null, + dropdownValue: requestsVM.requestTypeId.selectedId != -1 ? DropValue(requestsVM.requestTypeId.selectedId, requestsVM.requestTypeId.selectedOption, "") : null, hint: LocaleKeys.requestType.tr(), errorValue: requestsVM.requestTypeId.errorValue, ); @@ -78,24 +64,12 @@ class CreateRequestPage extends StatelessWidget { Builder(builder: (context) { List vehicleTypeDrop = []; for (var element in requestsVM.vehicleTypes) { - vehicleTypeDrop.add(DropValue( - element.id?.toInt() ?? 0, - element.vehicleTypeName ?? "", - "")); + vehicleTypeDrop.add(DropValue(element.id?.toInt() ?? 0, element.vehicleTypeName ?? "", "")); } return DropdownField( - (DropValue value) => requestsVM - .updateSelectionVehicleTypeId(SelectionModel( - selectedId: value.id, - selectedOption: value.value)), + (DropValue value) => requestsVM.updateSelectionVehicleTypeId(SelectionModel(selectedId: value.id, selectedOption: value.value)), list: vehicleTypeDrop, - dropdownValue: - requestsVM.vehicleTypeId.selectedId != -1 - ? DropValue( - requestsVM.vehicleTypeId.selectedId, - requestsVM.vehicleTypeId.selectedOption, - "") - : null, + dropdownValue: requestsVM.vehicleTypeId.selectedId != -1 ? DropValue(requestsVM.vehicleTypeId.selectedId, requestsVM.vehicleTypeId.selectedOption, "") : null, hint: LocaleKeys.vehicleType.tr(), errorValue: requestsVM.vehicleTypeId.errorValue, ); @@ -113,167 +87,78 @@ class CreateRequestPage extends StatelessWidget { Builder(builder: (context) { List vehicleBrandsDrop = []; for (var element in requestsVM.vehicleBrands) { - vehicleBrandsDrop.add(DropValue( - element.id?.toInt() ?? 0, - element.vehicleBrandDescription ?? "", - "")); + vehicleBrandsDrop.add(DropValue(element.id?.toInt() ?? 0, element.vehicleBrandDescription ?? "", "")); } return DropdownField( - (DropValue value) => - requestsVM.updateSelectionVehicleBrandId( - SelectionModel( - selectedId: value.id, - selectedOption: value.value)), + (DropValue value) => requestsVM.updateSelectionVehicleBrandId(SelectionModel(selectedId: value.id, selectedOption: value.value)), list: vehicleBrandsDrop, - dropdownValue: - requestsVM.vehicleBrandId.selectedId != -1 - ? DropValue( - requestsVM - .vehicleBrandId.selectedId, - requestsVM - .vehicleBrandId.selectedOption, - "") - : null, + dropdownValue: requestsVM.vehicleBrandId.selectedId != -1 ? DropValue(requestsVM.vehicleBrandId.selectedId, requestsVM.vehicleBrandId.selectedOption, "") : null, hint: LocaleKeys.brand.tr(), - errorValue: - requestsVM.vehicleBrandId.errorValue, + errorValue: requestsVM.vehicleBrandId.errorValue, ); }), 8.height, Builder(builder: (context) { List vehicleModelsDrop = []; for (var element in requestsVM.vehicleModels) { - if (requestsVM.vehicleBrandId.selectedId == - element.vehicleBrandID) - vehicleModelsDrop.add(DropValue( - element.id?.toInt() ?? 0, - element.model ?? "", - "")); + if (requestsVM.vehicleBrandId.selectedId == element.vehicleBrandID) vehicleModelsDrop.add(DropValue(element.id?.toInt() ?? 0, element.model ?? "", "")); } return DropdownField( - (DropValue value) => - requestsVM.updateSelectionVehicleModelId( - SelectionModel( - selectedId: value.id, - selectedOption: value.value)), + (DropValue value) => requestsVM.updateSelectionVehicleModelId(SelectionModel(selectedId: value.id, selectedOption: value.value)), list: vehicleModelsDrop, - dropdownValue: - requestsVM.vehicleModelId.selectedId != -1 - ? DropValue( - requestsVM - .vehicleModelId.selectedId, - requestsVM - .vehicleModelId.selectedOption, - "") - : null, + dropdownValue: requestsVM.vehicleModelId.selectedId != -1 ? DropValue(requestsVM.vehicleModelId.selectedId, requestsVM.vehicleModelId.selectedOption, "") : null, hint: LocaleKeys.model.tr(), - errorValue: - requestsVM.vehicleModelId.errorValue, + errorValue: requestsVM.vehicleModelId.errorValue, ); }), 8.height, Builder(builder: (context) { List vehicleYearModelsDrop = []; - for (var element - in requestsVM.vehicleModelYears) { - vehicleYearModelsDrop.add(DropValue( - element.id?.toInt() ?? 0, - element.modelYear ?? "", - "")); + for (var element in requestsVM.vehicleModelYears) { + vehicleYearModelsDrop.add(DropValue(element.id?.toInt() ?? 0, element.modelYear ?? "", "")); } return DropdownField( - (DropValue value) => requestsVM - .updateSelectionVehicleModelYearId( - SelectionModel( - selectedId: value.id, - selectedOption: value.value)), + (DropValue value) => requestsVM.updateSelectionVehicleModelYearId(SelectionModel(selectedId: value.id, selectedOption: value.value)), list: vehicleYearModelsDrop, - dropdownValue: - requestsVM.vehicleModelYearId.selectedId != - -1 - ? DropValue( - requestsVM - .vehicleModelYearId.selectedId, - requestsVM.vehicleModelYearId - .selectedOption, - "") - : null, + dropdownValue: requestsVM.vehicleModelYearId.selectedId != -1 ? DropValue(requestsVM.vehicleModelYearId.selectedId, requestsVM.vehicleModelYearId.selectedOption, "") : null, hint: LocaleKeys.year.tr(), - errorValue: - requestsVM.vehicleModelYearId.errorValue, + errorValue: requestsVM.vehicleModelYearId.errorValue, ); }), 8.height, Builder(builder: (context) { List vehicleCountriesDrop = []; for (var element in requestsVM.vehicleCountries) { - vehicleCountriesDrop.add(DropValue( - element.id?.toInt() ?? 0, - element.countryName ?? "", - "")); + vehicleCountriesDrop.add(DropValue(element.id?.toInt() ?? 0, element.countryName ?? "", "")); } return DropdownField( - (DropValue value) => - requestsVM.updateSelectionVehicleCountryId( - SelectionModel( - selectedOption: value.value, - selectedId: value.id)), + (DropValue value) => requestsVM.updateSelectionVehicleCountryId(SelectionModel(selectedOption: value.value, selectedId: value.id)), list: vehicleCountriesDrop, - dropdownValue: - requestsVM.vehicleCountryId.selectedId != -1 - ? DropValue( - requestsVM - .vehicleCountryId.selectedId, - requestsVM.vehicleCountryId - .selectedOption, - "") - : null, + dropdownValue: requestsVM.vehicleCountryId.selectedId != -1 ? DropValue(requestsVM.vehicleCountryId.selectedId, requestsVM.vehicleCountryId.selectedOption, "") : null, hint: LocaleKeys.country.tr(), - errorValue: - requestsVM.vehicleCountryId.errorValue, + errorValue: requestsVM.vehicleCountryId.errorValue, ); }), - if (requestsVM.vehicleCountryId.selectedId != - -1) ...[ + if (requestsVM.vehicleCountryId.selectedId != -1) ...[ if (requestsVM.isCountryFetching) ...[ Row( mainAxisAlignment: MainAxisAlignment.center, - children: [ - const CircularProgressIndicator() - .paddingAll(10) - ], + children: [const CircularProgressIndicator().paddingAll(10)], ), ] else ...[ 8.height, Builder(builder: (context) { List vehicleCitiesDrop = []; - for (var element - in requestsVM.vehicleCities) { - vehicleCitiesDrop.add(DropValue( - element.id?.toInt() ?? 0, - element.cityName ?? "", - "")); + for (var element in requestsVM.vehicleCities) { + vehicleCitiesDrop.add(DropValue(element.id?.toInt() ?? 0, element.cityName ?? "", "")); } return DropdownField( - (DropValue value) => - requestsVM.updateSelectionVehicleCityId( - SelectionModel( - selectedId: value.id, - selectedOption: value.value)), + (DropValue value) => requestsVM.updateSelectionVehicleCityId(SelectionModel(selectedId: value.id, selectedOption: value.value)), list: vehicleCitiesDrop, - dropdownValue: requestsVM - .vehicleCityId.selectedId != - -1 - ? DropValue( - requestsVM.vehicleCityId.selectedId, - requestsVM - .vehicleCityId.selectedOption, - "") - : null, + dropdownValue: requestsVM.vehicleCityId.selectedId != -1 ? DropValue(requestsVM.vehicleCityId.selectedId, requestsVM.vehicleCityId.selectedOption, "") : null, hint: LocaleKeys.city.tr(), - errorValue: - requestsVM.vehicleCityId.errorValue, + errorValue: requestsVM.vehicleCityId.errorValue, ); }), ], @@ -294,9 +179,7 @@ class CreateRequestPage extends StatelessWidget { ), 8.height, DottedRectContainer( - onTap: () => context - .read() - .pickMultipleImages(), + onTap: () => context.read().pickMultipleImages(), text: LocaleKeys.attachImage.tr(), icon: MyAssets.attachmentIcon.buildSvg(), ), @@ -305,8 +188,7 @@ class CreateRequestPage extends StatelessWidget { Row( mainAxisAlignment: MainAxisAlignment.end, children: [ - requestsVM.vehicleImageError - .toText(fontSize: 14, color: Colors.red), + requestsVM.vehicleImageError.toText(fontSize: 14, color: Colors.red), ], ).paddingOnly(right: 10) ], @@ -314,12 +196,9 @@ class CreateRequestPage extends StatelessWidget { 16.height, PickedFilesContainer( pickedFiles: requestsVM.pickedVehicleImages, - onCrossPressedPrimary: - requestsVM.removeImageFromList, + onCrossPressedPrimary: requestsVM.removeImageFromList, onAddFilePressed: () { - context - .read() - .pickMultipleImages(); + context.read().pickMultipleImages(); }, ), ], @@ -331,21 +210,16 @@ class CreateRequestPage extends StatelessWidget { value: requestsVM.isShippingDeliveryEnabled, onChanged: null, ), - LocaleKeys.shippingDelivery.tr().toText( - color: MyColors.darkPrimaryColor, - isBold: true, - fontSize: 18) + LocaleKeys.shippingDelivery.tr().toText(color: MyColors.darkPrimaryColor, isBold: true, fontSize: 18) ], ).onPress(() { - requestsVM.updateShippingDeliverEnabled( - !requestsVM.isShippingDeliveryEnabled); + requestsVM.updateShippingDeliverEnabled(!requestsVM.isShippingDeliveryEnabled); }), ], ), ] ], - ).toContainer( - isShadowEnabled: true, marginAll: 16, paddingAll: 12), + ).toContainer(isShadowEnabled: true, marginAll: 16, paddingAll: 12), ), ), ShowFillButton( diff --git a/lib/views/setting_options/provider_license_page.dart b/lib/views/setting_options/provider_license_page.dart index 2c10b16..742b68d 100644 --- a/lib/views/setting_options/provider_license_page.dart +++ b/lib/views/setting_options/provider_license_page.dart @@ -3,14 +3,11 @@ import 'dart:io'; 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/config/routes.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/models/general_models/generic_resp_model.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/view_models/service_view_model.dart'; @@ -18,11 +15,11 @@ 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 ProviderLicensePage extends StatefulWidget { + const ProviderLicensePage({super.key}); + @override State createState() => _ProviderLicensePageState(); } @@ -32,7 +29,6 @@ class _ProviderLicensePageState extends State { @override void initState() { - // TODO: implement initState super.initState(); branchVM = Provider.of(context, listen: false); branchVM.getServiceProviderDocument(AppState().getUser.data!.userInfo!.providerId ?? 0); @@ -93,17 +89,17 @@ class _ProviderLicensePageState extends State { validation(ServiceVM model) { bool valid = true; - model.document!.data!.forEach((element) { + for (var element in model.document!.data!) { if (element.documentUrl == null) { valid = false; } - }); + } return valid; } updateDocument(ServiceVM model) async { Utils.showLoading(context); - MResponse res = await model.updateDocument(model.document!.data); + GenericRespModel res = await model.updateDocument(model.document!.data); Utils.hideLoading(context); if (res.messageStatus == 1) { Utils.showToast(LocaleKeys.documentsUploadedSuccessfully.tr()); diff --git a/lib/views/setting_options/setting_options_language.dart b/lib/views/setting_options/setting_options_language.dart index 43fd943..2c8f19c 100644 --- a/lib/views/setting_options/setting_options_language.dart +++ b/lib/views/setting_options/setting_options_language.dart @@ -35,139 +35,138 @@ class SettingOptionsLanguage extends StatelessWidget { // ? Expanded( child: ListView( - shrinkWrap: true, - padding: EdgeInsets.zero, + shrinkWrap: true, + padding: EdgeInsets.zero, + children: [ + Column( children: [ - Column( - children: [ - CustomSettingOptionsTile( - leadingWidget: const Icon(Icons.quickreply_outlined, size: 20), - titleText: LocaleKeys.requests.tr(), - needBorderBelow: true, - onTap: () { - context.read().onNavbarTapped(4); - Navigator.pop(context); - }), - CustomSettingOptionsTile( - leadingWidget: const Icon(Icons.settings, size: 20), - titleText: LocaleKeys.settings.tr(), - needBorderBelow: true, - onTap: () {}, - //navigateWithName(context, AppRoutes.settingOptionsInviteFriends), - ), - CustomSettingOptionsTile( - leadingWidget: const Icon(Icons.question_mark_outlined, size: 20), - titleText: LocaleKeys.help.tr(), - needBorderBelow: true, - onTap: () => navigateWithName(context, AppRoutes.settingOptionsHelp), - ), - CustomSettingOptionsTile( - leadingWidget: const Icon(Icons.person, size: 20), - titleText: LocaleKeys.account.tr(), - needBorderBelow: false, - onTap: () { - navigateWithName(context, AppRoutes.profileView); - // context.read().onNavbarTapped(4); - // Navigator.pop(context); - }), - ], - ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0), - 10.height, CustomSettingOptionsTile( - leadingWidget: const Icon(Icons.translate, size: 20), - titleText: LocaleKeys.language.tr(), - isForLanguage: true, - onTap: () { - // if (EasyLocalization.of(context) - // ?.currentLocale - // ?.countryCode == - // "SA") { - // context.setLocale(const Locale("en", "US")); - // } else { - // context.setLocale(const Locale('ar', 'SA')); - // } - - context.read().changeLanguage(context); - }, - ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0), - 10.height, - (AppState().currentAppType == AppType.provider) - ? Column( - children: [ - CustomSettingOptionsTile( - leadingWidget: SizedBox( - width: 16, - height: 16, - child: SvgPicture.asset( - MyAssets.icStar, - color: MyColors.primaryColor, + leadingWidget: const Icon(Icons.quickreply_outlined, size: 20), + titleText: LocaleKeys.requests.tr(), + needBorderBelow: true, + onTap: () { + context.read().onNavbarTapped(4); + Navigator.pop(context); + }), + if (AppState().currentAppType == AppType.customer) ...[ + CustomSettingOptionsTile( + leadingWidget: const Icon(Icons.favorite, size: 20), + titleText: LocaleKeys.favoriteList.tr(), + needBorderBelow: true, + onTap: () => navigateWithName(context, AppRoutes.favoriteListView), + ), + ], + CustomSettingOptionsTile( + leadingWidget: const Icon(Icons.settings, size: 20), + titleText: LocaleKeys.settings.tr(), + needBorderBelow: true, + onTap: () {}, + //navigateWithName(context, AppRoutes.settingOptionsInviteFriends), + ), + CustomSettingOptionsTile( + leadingWidget: const Icon(Icons.question_mark_outlined, size: 20), + titleText: LocaleKeys.help.tr(), + needBorderBelow: true, + onTap: () => navigateWithName(context, AppRoutes.settingOptionsHelp), + ), + CustomSettingOptionsTile( + leadingWidget: const Icon(Icons.person, size: 20), + titleText: LocaleKeys.account.tr(), + needBorderBelow: false, + onTap: () { + navigateWithName(context, AppRoutes.profileView); + // context.read().onNavbarTapped(4); + // Navigator.pop(context); + }), + ], + ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0), + 10.height, + CustomSettingOptionsTile( + leadingWidget: const Icon(Icons.translate, size: 20), + titleText: LocaleKeys.language.tr(), + isForLanguage: true, + onTap: () { + context.read().changeLanguage(context); + }, + ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0), + 10.height, + (AppState().currentAppType == AppType.provider) + ? Column( + children: [ + CustomSettingOptionsTile( + leadingWidget: SizedBox( + width: 16, + height: 16, + child: SvgPicture.asset( + MyAssets.icStar, + color: MyColors.primaryColor, + ), ), + titleText: LocaleKeys.mySubscription.tr(), + subTitle: AppState().getproviderSubscription.first.subscriptionName ?? "Silver", + isForLanguage: false, + needBorderBelow: true, + onTap: () { + navigateWithName(context, AppRoutes.mySubscriptionsPage); + }, ), - titleText: LocaleKeys.mySubscription.tr(), - subTitle: AppState().getproviderSubscription.first.subscriptionName ?? "Silver", - isForLanguage: false, - needBorderBelow: true, - onTap: () { - navigateWithName(context, AppRoutes.mySubscriptionsPage); - }, - ), - CustomSettingOptionsTile( - leadingWidget: SizedBox( - width: 16, - height: 16, - child: SvgPicture.asset( - MyAssets.icGroupStar, - // color: MyColors.primaryColor, + CustomSettingOptionsTile( + leadingWidget: SizedBox( + width: 16, + height: 16, + child: SvgPicture.asset( + MyAssets.icGroupStar, + // color: MyColors.primaryColor, + ), ), + titleText: LocaleKeys.subscriptions.tr(), + subTitle: null, + isForLanguage: false, + needBorderBelow: true, + onTap: () { + navigateWithName(context, AppRoutes.subscriptionsPage); + }, ), - titleText: LocaleKeys.subscriptions.tr(), - subTitle: null, - isForLanguage: false, - needBorderBelow: true, - onTap: () { - navigateWithName(context, AppRoutes.subscriptionsPage); - }, - ), - CustomSettingOptionsTile( - leadingWidget: SizedBox( - width: 16, - height: 16, - child: SvgPicture.asset( - MyAssets.icGroupStar, - // color: MyColors.primaryColor, + CustomSettingOptionsTile( + leadingWidget: SizedBox( + width: 16, + height: 16, + child: SvgPicture.asset( + MyAssets.icGroupStar, + // color: MyColors.primaryColor, + ), ), + titleText: LocaleKeys.defineLicenses.tr(), + subTitle: null, + isForLanguage: false, + needBorderBelow: false, + onTap: () { + navigateWithName(context, AppRoutes.providerLicensePage); + }, ), - titleText: LocaleKeys.defineLicenses.tr(), - subTitle: null, - isForLanguage: false, - needBorderBelow: false, - onTap: () { - navigateWithName(context, AppRoutes.providerLicensePage); - }, - ), - // CustomSettingOptionsTile( - // leadingWidget: SizedBox( - // width: 16, - // height: 16, - // child: SvgPicture.asset( - // MyAssets.providersIcon, - // // color: MyColors.primaryColor, - // ), - // ), - // titleText: "Users", - // subTitle: null, - // isForLanguage: false, - // needBorderBelow: false, - // onTap: () { - // navigateWithName(context, AppRoutes.dealerUser, arguments: AppState().getUser.data!.userInfo!.id.toString()); - // }, - // ) - ], - ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0) - : SizedBox(), - (AppState().currentAppType == AppType.provider) ? 10.height : SizedBox(), - ], - )), + // CustomSettingOptionsTile( + // leadingWidget: SizedBox( + // width: 16, + // height: 16, + // child: SvgPicture.asset( + // MyAssets.providersIcon, + // // color: MyColors.primaryColor, + // ), + // ), + // titleText: "Users", + // subTitle: null, + // isForLanguage: false, + // needBorderBelow: false, + // onTap: () { + // navigateWithName(context, AppRoutes.dealerUser, arguments: AppState().getUser.data!.userInfo!.id.toString()); + // }, + // ) + ], + ).toWhiteContainer(width: double.infinity, pading: const EdgeInsets.all(12), borderRadius: 0) + : const SizedBox(), + (AppState().currentAppType == AppType.provider) ? 10.height : const SizedBox(), + ], + )), // : Expanded( // child: ListView( // children: [ diff --git a/lib/widgets/common_widgets/branch_details_card.dart b/lib/widgets/common_widgets/branch_details_card.dart new file mode 100644 index 0000000..e376714 --- /dev/null +++ b/lib/widgets/common_widgets/branch_details_card.dart @@ -0,0 +1,122 @@ +import 'package:easy_localization/easy_localization.dart'; +import 'package:flutter/material.dart'; +import 'package:mc_common_app/classes/consts.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/services_models/service_model.dart'; +import 'package:mc_common_app/theme/colors.dart'; +import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; + +class BranchDetailCard extends StatelessWidget { + final String providerImageUrl; + final String title; + final String? providerName; + final String providerLocation; + final double providerRatings; + final List? services; + final Function() onCardTapped; + + const BranchDetailCard({ + Key? key, + required this.providerImageUrl, + required this.title, + required this.providerRatings, + required this.providerLocation, + this.services, + this.providerName, + required this.onCardTapped, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Padding( + padding: EdgeInsets.zero, + // padding: const EdgeInsets.only( + // bottom: 10, + // left: 21, + // right: 21, + // ), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + providerImageUrl.buildNetworkImage(height: 80, width: 80), + 12.width, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + title.toText(fontSize: 16, isBold: true), + Row( + children: [ + ("${LocaleKeys.location.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12), + 4.width, + providerLocation.toText(fontSize: 12, isBold: true), + ], + ), + if (providerName != null) + Row( + children: [ + ("${LocaleKeys.providers.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12), + 4.width, + providerName!.toText(fontSize: 12, isBold: true), + ], + ), + ], + ), + ), + if (providerRatings != 0.0) ...[ + Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + providerRatings.toString().toText( + isUnderLine: true, + isBold: true, + fontSize: 12, + ), + 2.width, + MyAssets.icStar.buildSvg(width: 12), + ], + ), + ], + ], + ), + 8.height, + if (services != null) + Column( + children: services! + .take(2) + .map( + (e) => Row( + children: [ + //TODO: Needs to add icon in the future when added from the provider + // MyAssets.maintenanceIcon.buildSvg(), + // 8.width, + e.serviceDescription.toString().toText(fontSize: 12) + ], + ), + ) + .toList(), + ), + if (services != null && services!.length > 2) + ("+${services!.length - 2} more").toText( + color: MyColors.primaryColor, + isUnderLine: true, + isBold: true, + ), + ], + ), + ), + ], + ).onPress(onCardTapped).toWhiteContainer(width: double.infinity, allPading: 12)); + } +} diff --git a/lib/widgets/common_widgets/provider_details_card.dart b/lib/widgets/common_widgets/provider_details_card.dart index 554b3d7..1bffb86 100644 --- a/lib/widgets/common_widgets/provider_details_card.dart +++ b/lib/widgets/common_widgets/provider_details_card.dart @@ -4,127 +4,87 @@ import 'package:mc_common_app/classes/consts.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/provider_branches_models/branch_detail_model.dart'; import 'package:mc_common_app/models/services_models/service_model.dart'; import 'package:mc_common_app/theme/colors.dart'; import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; -class ProviderDetailsCard extends StatelessWidget { +class ProviderDetailCard extends StatelessWidget { final String providerImageUrl; final String title; - final String? providerName; - final String providerLocation; - final double providerRatings; - - //TODO: items can be make a generaic, so we can add services/items in the future - final List? services; + final String startedSince; + final String totalBranches; + final String description; + final List branches; final Function() onCardTapped; - const ProviderDetailsCard({ + const ProviderDetailCard({ Key? key, required this.providerImageUrl, required this.title, - required this.providerRatings, - required this.providerLocation, - this.services, - this.providerName, + required this.totalBranches, + required this.branches, + required this.description, + required this.startedSince, required this.onCardTapped, }) : super(key: key); @override Widget build(BuildContext context) { - //TODO: use pading in listview - return Padding( - padding: EdgeInsets.zero, - // padding: const EdgeInsets.only( - // bottom: 10, - // left: 21, - // right: 21, - // ), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Image.asset( - providerImageUrl, - width: 80, - height: 85, - fit: BoxFit.cover, - ), - 12.width, - Expanded( - child: Column( + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Image.asset( + providerImageUrl, + width: 80, + height: 85, + fit: BoxFit.cover, + ), + 12.width, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ - Row( - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + title.toText(fontSize: 16, isBold: true), + Row( children: [ - title.toText(fontSize: 16, isBold: true), - Row( - children: [ - ("${LocaleKeys.location.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12), - 4.width, - providerLocation.toText(fontSize: 12, isBold: true), - ], - ), - if (providerName != null) - Row( - children: [ - ("${LocaleKeys.providers.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12), - 4.width, - providerName!.toText(fontSize: 12, isBold: true), - ], - ), + ("Total Branches:").toText(color: MyColors.lightTextColor, fontSize: 12), + 4.width, + totalBranches.toText(fontSize: 12, isBold: true), ], ), - ), - if (providerRatings != 0.0) ...[ Row( - mainAxisAlignment: MainAxisAlignment.start, children: [ - providerRatings.toString().toText( - isUnderLine: true, - isBold: true, - fontSize: 12, - ), - 2.width, - MyAssets.icStar.buildSvg(width: 12), + ("${LocaleKeys.description.tr()}:").toText(color: MyColors.lightTextColor, fontSize: 12), + 4.width, + description.toText(fontSize: 12, isBold: true), + ], + ), + Row( + children: [ + ("Since:").toText(color: MyColors.lightTextColor, fontSize: 12), + 4.width, + startedSince.toText(fontSize: 12, isBold: true), ], ), ], - ], - ), - 8.height, - if (services != null) - Column( - children: services! - .take(2) - .map( - (e) => Row( - children: [ - //TODO: Needs to add icon in the future when added from the provider - // MyAssets.maintenanceIcon.buildSvg(), - // 8.width, - e.serviceDescription.toString().toText(fontSize: 12) - ], - ), - ) - .toList(), - ), - if (services != null && services!.length > 2) - ("+${services!.length - 2} more").toText( - color: MyColors.primaryColor, - isUnderLine: true, - isBold: true, ), + ), ], ), - ), - ], - ).onPress(onCardTapped).toWhiteContainer(width: double.infinity, allPading: 12)); + ], + ), + ), + ], + ).onPress(onCardTapped).toWhiteContainer(width: double.infinity, allPading: 12); } } diff --git a/lib/widgets/extensions/extensions_widget.dart b/lib/widgets/extensions/extensions_widget.dart index f8998cd..afbacea 100644 --- a/lib/widgets/extensions/extensions_widget.dart +++ b/lib/widgets/extensions/extensions_widget.dart @@ -2,6 +2,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:mc_common_app/classes/consts.dart'; +import 'package:mc_common_app/main.dart'; import 'package:mc_common_app/theme/colors.dart'; import 'package:provider/provider.dart'; @@ -31,13 +32,18 @@ extension ContainerExt on Widget { border: isBorderRequired ? Border.all(color: MyColors.darkPrimaryColor, width: 2) : null, color: backgroundColor ?? MyColors.white, borderRadius: BorderRadius.circular(borderRadius), - boxShadow: const [ + boxShadow: [ BoxShadow( - blurRadius: 8, - spreadRadius: 3, - offset: Offset(0, 3), - color: MyColors.greyShadowColor, + color: const Color(0xff000000).withOpacity(.07), + blurRadius: 26, + offset: const Offset(0, -3), ), + // BoxShadow( + // blurRadius: 8, + // spreadRadius: 3, + // offset: Offset(0, 3), + // color: MyColors.greyShadowColor, + // ), ], ), padding: pading ?? EdgeInsets.all(allPading ?? 0), @@ -77,12 +83,12 @@ extension ContainerExt on Widget { boxShadow: !isShadowEnabled ? null : [ - BoxShadow( - color: const Color(0xff000000).withOpacity(.05), - blurRadius: 26, - offset: const Offset(0, -3), - ), - ], + BoxShadow( + color: const Color(0xff000000).withOpacity(.05), + blurRadius: 26, + offset: const Offset(0, -3), + ), + ], ), padding: padding ?? EdgeInsets.all(paddingAll), margin: margin ?? EdgeInsets.all(marginAll), @@ -227,8 +233,7 @@ extension WidgetExt on Widget { ); } - Widget paddingOnly({double left = 0.0, double right = 0.0, double top = 0.0, double bottom = 0.0}) => - Padding(padding: EdgeInsets.only(left: left, right: right, top: top, bottom: bottom), child: this); + Widget paddingOnly({double left = 0.0, double right = 0.0, double top = 0.0, double bottom = 0.0}) => Padding(padding: EdgeInsets.only(left: left, right: right, top: top, bottom: bottom), child: this); // Widget onTap(VoidCallback onTap, {double corners = 0}) { // return Clickable.widget(child: this, corners: corners, onTap: onTap); @@ -329,10 +334,39 @@ extension xDouble on int { Duration durationHour() => Duration(hours: this); } -extension BuildSVG on String { +extension BuildSVG on String? { Widget buildSvg({double? height, double? width, BoxFit fit = BoxFit.contain, Color? color}) { return SvgPicture.asset( - this, + this!, + fit: fit, + color: color, + height: height, + width: width, + ); + } + + Widget buildNetworkImage({double? height, double? width, BoxFit fit = BoxFit.contain, Color? color}) { + if (this == null || this!.isEmpty) { + return SizedBox( + height: height, + width: width, + child: const Icon(Icons.error_outline_rounded), + ); + } + + return Image.network( + this!, + errorBuilder: (BuildContext context, Object obj, StackTrace? s) { + return SizedBox(height: height, width: width, child: const Icon(Icons.signal_wifi_connected_no_internet_4_outlined)); + }, + loadingBuilder: (BuildContext context, Widget? child, ImageChunkEvent? imageChunk) { + return const Center( + child: CircularProgressIndicator( + strokeWidth: 0.5, + color: MyColors.darkPrimaryColor, + ), + ); + }, fit: fit, color: color, height: height, @@ -343,18 +377,10 @@ extension BuildSVG on String { extension LocaleSetup on MultiProvider { Widget setupLocale() { - return EasyLocalization( - supportedLocales: MyLocales.supportedLocales, - fallbackLocale: MyLocales.fallBackLocale, - startLocale: MyLocales.startLocale, - assetLoader: MyLocales.assetLoader, - path: MyLocales.localesAssetPath, - child: this); + return EasyLocalization(supportedLocales: MyLocales.supportedLocales, fallbackLocale: MyLocales.fallBackLocale, startLocale: MyLocales.startLocale, assetLoader: MyLocales.assetLoader, path: MyLocales.localesAssetPath, child: this); } } extension WidgetExtensions on Widget { Widget onPress(VoidCallback onTap) => InkWell(onTap: onTap, child: this); } - -