diff --git a/android/app/build.gradle b/android/app/build.gradle index 1023e29..3f54788 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -22,6 +22,8 @@ if (flutterVersionName == null) { } apply plugin: 'com.android.application' +apply plugin: 'com.google.gms.google-services' + apply plugin: 'kotlin-android' apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle" @@ -43,7 +45,7 @@ android { defaultConfig { // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html). - applicationId "com.example.car_customer_app" + applicationId "com.cloud.solutions.mowater.ksa.customer" minSdkVersion 23 targetSdkVersion 33 versionCode flutterVersionCode.toInteger() @@ -65,4 +67,8 @@ flutter { dependencies { implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation platform('com.google.firebase:firebase-bom:33.1.2') +// implementation 'com.google.firebase:firebase-analytics' } + + diff --git a/android/app/google-services.json b/android/app/google-services.json new file mode 100644 index 0000000..ed4c547 --- /dev/null +++ b/android/app/google-services.json @@ -0,0 +1,48 @@ +{ + "project_info": { + "project_number": "294636898500", + "project_id": "mowater-2c81a", + "storage_bucket": "mowater-2c81a.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:294636898500:android:f2f4ae08e5641216b0e191", + "android_client_info": { + "package_name": "com.cloud.solutions.mowater.ksa.customer" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyD1WNNGrbBiCNvCrI31d3DV5AOgToq-Lus" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + }, + { + "client_info": { + "mobilesdk_app_id": "1:294636898500:android:e93b7e5d1cc15ae6b0e191", + "android_client_info": { + "package_name": "com.cloud.solutions.mowater.ksa.provider" + } + }, + "oauth_client": [], + "api_key": [ + { + "current_key": "AIzaSyD1WNNGrbBiCNvCrI31d3DV5AOgToq-Lus" + } + ], + "services": { + "appinvite_service": { + "other_platform_oauth_client": [] + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/android/app/src/debug/AndroidManifest.xml b/android/app/src/debug/AndroidManifest.xml index c73ec18..c12869c 100644 --- a/android/app/src/debug/AndroidManifest.xml +++ b/android/app/src/debug/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.cloud.solutions.mowater.ksa.customer"> diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 92bc5c2..7014bd2 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.cloud.solutions.mowater.ksa.customer"> @@ -9,7 +9,7 @@ + + + + diff --git a/android/app/src/main/kotlin/com/example/car_customer_app/MainActivity.kt b/android/app/src/main/kotlin/com/example/car_customer_app/MainActivity.kt deleted file mode 100644 index 9860bc3..0000000 --- a/android/app/src/main/kotlin/com/example/car_customer_app/MainActivity.kt +++ /dev/null @@ -1,6 +0,0 @@ -package com.example.car_customer_app - -import io.flutter.embedding.android.FlutterActivity - -class MainActivity: FlutterActivity() { -} diff --git a/android/app/src/main/res/drawable/ic_launcher.png b/android/app/src/main/res/drawable/ic_launcher.png new file mode 100644 index 0000000..4d6372e Binary files /dev/null and b/android/app/src/main/res/drawable/ic_launcher.png differ diff --git a/android/app/src/profile/AndroidManifest.xml b/android/app/src/profile/AndroidManifest.xml index c73ec18..c12869c 100644 --- a/android/app/src/profile/AndroidManifest.xml +++ b/android/app/src/profile/AndroidManifest.xml @@ -1,5 +1,5 @@ + package="com.cloud.solutions.mowater.ksa.customer"> diff --git a/android/build.gradle b/android/build.gradle index aca8b4a..d7a7530 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -8,9 +8,12 @@ buildscript { dependencies { classpath 'com.android.tools.build:gradle:7.4.2' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.google.gms:google-services:4.4.2' + } } + allprojects { repositories { google() @@ -18,6 +21,7 @@ allprojects { } } + rootProject.buildDir = '../build' subprojects { project.buildDir = "${rootProject.buildDir}/${project.name}" diff --git a/ios/Runner.xcodeproj/project.pbxproj b/ios/Runner.xcodeproj/project.pbxproj index ecb319a..cc6f25b 100644 --- a/ios/Runner.xcodeproj/project.pbxproj +++ b/ios/Runner.xcodeproj/project.pbxproj @@ -13,7 +13,6 @@ 97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; }; 97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; }; 97C147011CF9000F007C117D /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FF1CF9000F007C117D /* LaunchScreen.storyboard */; }; - F385BE1E015F5F197DDC457E /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 9CA04DE821BC910C56C29F5B /* Pods_Runner.framework */; }; /* End PBXBuildFile section */ /* Begin PBXCopyFilesBuildPhase section */ @@ -32,9 +31,7 @@ /* Begin PBXFileReference section */ 1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = ""; }; 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = ""; }; - 3643750A79F4A25346F39B6F /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = ""; }; 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = ""; }; - 4F0574D3DCBBF0F35A33896D /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = ""; }; 74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = ""; }; 74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = ""; }; @@ -45,8 +42,6 @@ 97C146FD1CF9000F007C117D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 97C147001CF9000F007C117D /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 97C147021CF9000F007C117D /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; - 9CA04DE821BC910C56C29F5B /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; }; - C74C73D850C4D4FC94940060 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -54,7 +49,6 @@ isa = PBXFrameworksBuildPhase; buildActionMask = 2147483647; files = ( - F385BE1E015F5F197DDC457E /* Pods_Runner.framework in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -64,21 +58,10 @@ 83F33F395D7AA87F2A896F35 /* Pods */ = { isa = PBXGroup; children = ( - 4F0574D3DCBBF0F35A33896D /* Pods-Runner.debug.xcconfig */, - C74C73D850C4D4FC94940060 /* Pods-Runner.release.xcconfig */, - 3643750A79F4A25346F39B6F /* Pods-Runner.profile.xcconfig */, ); path = Pods; sourceTree = ""; }; - 96061B8FD0BBF121A96FFCF3 /* Frameworks */ = { - isa = PBXGroup; - children = ( - 9CA04DE821BC910C56C29F5B /* Pods_Runner.framework */, - ); - name = Frameworks; - sourceTree = ""; - }; 9740EEB11CF90186004384FC /* Flutter */ = { isa = PBXGroup; children = ( @@ -97,7 +80,6 @@ 97C146F01CF9000F007C117D /* Runner */, 97C146EF1CF9000F007C117D /* Products */, 83F33F395D7AA87F2A896F35 /* Pods */, - 96061B8FD0BBF121A96FFCF3 /* Frameworks */, ); sourceTree = ""; }; @@ -131,15 +113,12 @@ isa = PBXNativeTarget; buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */; buildPhases = ( - F3B998BE4409F6FFB76727BB /* [CP] Check Pods Manifest.lock */, 9740EEB61CF901F6004384FC /* Run Script */, 97C146EA1CF9000F007C117D /* Sources */, 97C146EB1CF9000F007C117D /* Frameworks */, 97C146EC1CF9000F007C117D /* Resources */, 9705A1C41CF9048500538489 /* Embed Frameworks */, 3B06AD1E1E4923F5004D2608 /* Thin Binary */, - 9A2045E27F192C87BCD2FA50 /* [CP] Embed Pods Frameworks */, - 4CC2E88FCFA89EAD7EEA637B /* [CP] Copy Pods Resources */, ); buildRules = ( ); @@ -214,23 +193,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" embed_and_thin"; }; - 4CC2E88FCFA89EAD7EEA637B /* [CP] Copy Pods Resources */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Copy Pods Resources"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-resources.sh\"\n"; - showEnvVarsInLog = 0; - }; 9740EEB61CF901F6004384FC /* Run Script */ = { isa = PBXShellScriptBuildPhase; alwaysOutOfDate = 1; @@ -246,45 +208,6 @@ shellPath = /bin/sh; shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build"; }; - 9A2045E27F192C87BCD2FA50 /* [CP] Embed Pods Frameworks */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist", - ); - name = "[CP] Embed Pods Frameworks"; - outputFileListPaths = ( - "${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n"; - showEnvVarsInLog = 0; - }; - F3B998BE4409F6FFB76727BB /* [CP] Check Pods Manifest.lock */ = { - isa = PBXShellScriptBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - inputFileListPaths = ( - ); - inputPaths = ( - "${PODS_PODFILE_DIR_PATH}/Podfile.lock", - "${PODS_ROOT}/Manifest.lock", - ); - name = "[CP] Check Pods Manifest.lock"; - outputFileListPaths = ( - ); - outputPaths = ( - "$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt", - ); - runOnlyForDeploymentPostprocessing = 0; - shellPath = /bin/sh; - shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; - showEnvVarsInLog = 0; - }; /* End PBXShellScriptBuildPhase section */ /* Begin PBXSourcesBuildPhase section */ @@ -384,7 +307,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.carCustomerApp; + PRODUCT_BUNDLE_IDENTIFIER = com.cloud.solutions.mowater.ksa.customer; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; @@ -514,7 +437,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.carCustomerApp; + PRODUCT_BUNDLE_IDENTIFIER = com.cloud.solutions.mowater.ksa.customer; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_OPTIMIZATION_LEVEL = "-Onone"; @@ -538,7 +461,7 @@ "$(inherited)", "@executable_path/Frameworks", ); - PRODUCT_BUNDLE_IDENTIFIER = com.example.carCustomerApp; + PRODUCT_BUNDLE_IDENTIFIER = com.cloud.solutions.mowater.ksa.customer; PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_OBJC_BRIDGING_HEADER = "Runner/Runner-Bridging-Header.h"; SWIFT_VERSION = 5.0; diff --git a/ios/Runner/AppDelegate.swift b/ios/Runner/AppDelegate.swift index 70693e4..009aa8f 100644 --- a/ios/Runner/AppDelegate.swift +++ b/ios/Runner/AppDelegate.swift @@ -1,5 +1,7 @@ import UIKit import Flutter +import GoogleMaps + @UIApplicationMain @objc class AppDelegate: FlutterAppDelegate { @@ -7,6 +9,16 @@ import Flutter _ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? ) -> Bool { + + // This is required to make any communication available in the action isolate. + FlutterLocalNotificationsPlugin.setPluginRegistrantCallback { (registry) in + GeneratedPluginRegistrant.register(with: registry) + } + + if #available(iOS 10.0, *) { + UNUserNotificationCenter.current().delegate = self as UNUserNotificationCenterDelegate + } + GMSServices.provideAPIKey("AIzaSyCyDbWUM9d_sBUGIE8PcuShzPaqO08NSC8") GeneratedPluginRegistrant.register(with: self) return super.application(application, didFinishLaunchingWithOptions: launchOptions) } diff --git a/ios/Runner/GoogleService-Info.plist b/ios/Runner/GoogleService-Info.plist new file mode 100644 index 0000000..b7301b9 --- /dev/null +++ b/ios/Runner/GoogleService-Info.plist @@ -0,0 +1,30 @@ + + + + + API_KEY + AIzaSyAQoUIOm-5FtUqUngK0zvkkF2fafRxsm_I + GCM_SENDER_ID + 294636898500 + PLIST_VERSION + 1 + BUNDLE_ID + com.cloud.solutions.mowater.ksa.customer.ios + PROJECT_ID + mowater-2c81a + STORAGE_BUCKET + mowater-2c81a.appspot.com + IS_ADS_ENABLED + + IS_ANALYTICS_ENABLED + + IS_APPINVITE_ENABLED + + IS_GCM_ENABLED + + IS_SIGNIN_ENABLED + + GOOGLE_APP_ID + 1:294636898500:ios:b47422d0ef4ca385b0e191 + + \ No newline at end of file diff --git a/lib/config/customer_dependencies.dart b/lib/config/customer_dependencies.dart index 252b4f9..31ca553 100644 --- a/lib/config/customer_dependencies.dart +++ b/lib/config/customer_dependencies.dart @@ -1,5 +1,5 @@ -import 'package:mc_common_app/config/dependencies.dart'; +import 'package:mc_common_app/config/dependency_injection.dart'; class CustomerDependencies { static void addDependencies() { diff --git a/lib/config/customer_routes.dart b/lib/config/customer_routes.dart index 8dd5b44..52cdf0d 100644 --- a/lib/config/customer_routes.dart +++ b/lib/config/customer_routes.dart @@ -48,9 +48,7 @@ class CustomerAppRoutes { AppRoutes.providerProfilePage: (context) => ProviderProfilePage(providerId: ModalRoute.of(context)!.settings.arguments as int), AppRoutes.offersListPage: (context) => OfferListPage(offerListPageArguments: ModalRoute.of(context)!.settings.arguments as OfferListPageArguments), AppRoutes.createRequestPage: (context) => CreateRequestPage(), - AppRoutes.chatView: (context) => ChatView( - chatViewArguments: ModalRoute.of(context)!.settings.arguments as ChatViewArguments, - ), + AppRoutes.chatView: (context) => ChatView(chatViewArguments: ModalRoute.of(context)!.settings.arguments as ChatViewArguments), AppRoutes.settingOptionsFaqs: (context) => SettingOptionsFAQs(), AppRoutes.settingOptionsLanguages: (context) => SettingOptionsLanguage(), AppRoutes.settingOptionsInviteFriends: (context) => SettingOptionsInviteFriends(), diff --git a/lib/main.dart b/lib/main.dart index b77fab5..99acad9 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -4,6 +4,7 @@ import 'package:mc_common_app/repositories/branch_repo.dart'; import 'package:mc_common_app/repositories/chat_repo.dart'; import 'package:mc_common_app/repositories/appointment_repo.dart'; import 'package:mc_common_app/repositories/request_repo.dart'; +import 'package:mc_common_app/services/firebase_service.dart'; import 'package:mc_common_app/view_models/appointments_view_model.dart'; import 'package:mc_common_app/view_models/chat_view_model.dart'; import 'package:mc_common_app/view_models/dashboard_view_model_customer.dart'; @@ -11,7 +12,7 @@ import 'package:mc_common_app/view_models/requests_view_model.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:mc_common_app/classes/app_state.dart'; -import 'package:mc_common_app/config/dependencies.dart'; +import 'package:mc_common_app/config/dependency_injection.dart'; import 'package:mc_common_app/config/routes.dart'; import 'package:mc_common_app/models/general_models/post_params_model.dart'; import 'package:mc_common_app/repositories/ads_repo.dart'; @@ -31,14 +32,24 @@ import 'package:provider/provider.dart'; import 'package:provider/single_child_widget.dart'; import 'package:sizer/sizer.dart'; import 'package:intl/date_symbol_data_local.dart'; +import 'package:firebase_core/firebase_core.dart'; final navigatorKey = GlobalKey(); //test commit Future main() async { WidgetsFlutterBinding.ensureInitialized(); - CustomerDependencies.addDependencies(); await EasyLocalization.ensureInitialized(); + await Firebase.initializeApp( + options: const FirebaseOptions( + apiKey: 'AIzaSyD1WNNGrbBiCNvCrI31d3DV5AOgToq-Lus', + appId: '1:294636898500:android:e93b7e5d1cc15ae6b0e191', + messagingSenderId: '294636898500', + projectId: 'mowater-2c81a', + )); + + CustomerDependencies.addDependencies(); + injector.get().initializeNotifications(); CustomerAppRoutes.routes.addAll(AppRoutes.routes); initializeDateFormatting().then((_) => runApp( MultiProvider( diff --git a/lib/views/dashboard/dashboard_page.dart b/lib/views/dashboard/dashboard_page.dart index 4c227cc..9f790c2 100644 --- a/lib/views/dashboard/dashboard_page.dart +++ b/lib/views/dashboard/dashboard_page.dart @@ -13,13 +13,10 @@ 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/widgets_models.dart'; import 'package:mc_common_app/theme/colors.dart'; -import 'package:mc_common_app/utils/enums.dart'; import 'package:mc_common_app/utils/navigator.dart'; import 'package:mc_common_app/view_models/ad_view_model.dart'; import 'package:mc_common_app/view_models/appointments_view_model.dart'; -import 'package:mc_common_app/view_models/chat_view_model.dart'; import 'package:mc_common_app/view_models/dashboard_view_model_customer.dart'; import 'package:mc_common_app/view_models/requests_view_model.dart'; import 'package:mc_common_app/widgets/common_widgets/app_bar.dart'; @@ -36,68 +33,18 @@ class DashboardPage extends StatefulWidget { } class _DashboardPageState extends State { - // late DashboardVM dashboardVM; + late DashboardVmCustomer dashboardVM; @override void initState() { super.initState(); - // dashboardVM = Provider.of(context, listen: false); + dashboardVM = Provider.of(context, listen: false); scheduleMicrotask(() { - onInitState(); - _onRefresh(); + dashboardVM.onInitState(context); + dashboardVM.onRefresh(context); }); } - onInitState() async { - Future.wait([ - context.read().populateAppointmentsFilterList(), - context.read().populateBranchesFilterList(), - context.read().populateRequestsFilterList(), - context.read().populateAdsFilterList(), - ]); - } - - Future _onRefresh() async { - AdVM adVM = Provider.of(context, listen: false); - AppointmentsVM appointmentsVM = Provider.of(context, listen: false); - RequestsVM requestsVM = Provider.of(context, listen: false); - ChatVM chatVM = Provider.of(context, listen: false); - if (appointmentsVM.myAppointments.isEmpty) { - await appointmentsVM.getMyAppointments(); - } - - if (appointmentsVM.nearbyBranches.isEmpty) { - await appointmentsVM.applyFilterOnBranches(index: 0); // to get all branches! - } - - if (adVM.myAds.isEmpty) { - await adVM.getMyAds(); - } - if (adVM.exploreAds.isEmpty) { - await adVM.getExploreAds(); - } - if (requestsVM.myRequests.isEmpty) { - await requestsVM.getRequests(appType: AppType.customer); - } - - if (adVM.vehicleTypes.isEmpty) { - await adVM.getVehicleTypes(); - } - - if (adVM.vehicleAdsDurations.isEmpty) { - await adVM.getVehicleAdsDuration(); - } - - await chatVM.buildHubConnection(context); - adVM.updateVehicleAdDurationId( - SelectionModel( - selectedId: adVM.vehicleAdsDurations.first.id ?? 0, - selectedOption: "${adVM.vehicleAdsDurations.first.days} Days", - itemPrice: adVM.vehicleAdsDurations.first.price!.toInt().toString(), - ), - ); - } - List fragments = [ const BranchesFragment(), const AppointmentsFragment(), diff --git a/lib/views/dashboard/fragments/ads_fragment.dart b/lib/views/dashboard/fragments/ads_fragment.dart index 10cde5a..5b9fa44 100644 --- a/lib/views/dashboard/fragments/ads_fragment.dart +++ b/lib/views/dashboard/fragments/ads_fragment.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mc_common_app/classes/app_state.dart'; -import 'package:mc_common_app/config/dependencies.dart'; +import 'package:mc_common_app/config/dependency_injection.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'; diff --git a/lib/views/dashboard/fragments/home_fragment.dart b/lib/views/dashboard/fragments/home_fragment.dart index e6e6098..e892e7a 100644 --- a/lib/views/dashboard/fragments/home_fragment.dart +++ b/lib/views/dashboard/fragments/home_fragment.dart @@ -14,7 +14,6 @@ import 'package:mc_common_app/widgets/extensions/extensions_widget.dart'; import 'package:provider/provider.dart'; import 'package:easy_localization/easy_localization.dart'; - class HomeFragment extends StatelessWidget { const HomeFragment({Key? key}) : super(key: key); @@ -22,88 +21,95 @@ class HomeFragment extends StatelessWidget { Widget build(BuildContext context) { return Scaffold( drawer: CustomDrawer(dashboardVM: context.watch()), - body: SizedBox( - width: double.infinity, - height: double.infinity, - child: SingleChildScrollView( - child: Padding( - padding: const EdgeInsets.only(top: 8), - child: Column( - mainAxisSize: MainAxisSize.max, - children: [ - 16.height, - ViewAllWidget( - title: LocaleKeys.upcoming_appointment.tr().toUpperCase(), - subTitle: LocaleKeys.view_all.tr(), - onSubtitleTapped: () { - context.read().onNavbarTapped(1); - context.read().applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments); - }, - ).horPaddingMain(), - CustomerAppointmentSliderWidget(myUpComingAppointments: context.read().myUpComingAppointments), - 7.height, - ViewAllWidget( - title: LocaleKeys.my_recent_providers.tr().toUpperCase(), + body: RefreshIndicator( + onRefresh: () async { + context.read().onInitState(context); + context.read().onRefresh(context); + return; + }, + child: SizedBox( + width: double.infinity, + height: double.infinity, + child: SingleChildScrollView( + child: Padding( + padding: const EdgeInsets.only(top: 8), + child: Column( + mainAxisSize: MainAxisSize.max, + children: [ + 16.height, + ViewAllWidget( + title: LocaleKeys.upcoming_appointment.tr().toUpperCase(), subTitle: LocaleKeys.view_all.tr(), onSubtitleTapped: () { - context.read().onNavbarTapped(0); - context.read().applyFilterOnBranches(index: 0); - }).horPaddingMain(), - Consumer(builder: (BuildContext context, AppointmentsVM appointmentsVM, Widget? child) { - return ServiceProviderWidget(nearbyBranches: context.read().nearbyBranches).horPaddingMain(); - }), - Consumer( - builder: (BuildContext context, AdVM adVM, Widget? child) { - return Column( - children: [ - if (adVM.myActiveAdsForHome.isNotEmpty) ...[ - Column( - children: [ - 15.height, - ViewAllWidget( - title: LocaleKeys.my_active_Ads.tr().toUpperCase(), + context.read().onNavbarTapped(1); + context.read().applyFilterOnAppointmentsVM(appointmentStatusEnum: AppointmentStatusEnum.allAppointments); + }, + ).horPaddingMain(), + CustomerAppointmentSliderWidget(), + 7.height, + ViewAllWidget( + title: LocaleKeys.my_recent_providers.tr().toUpperCase(), + subTitle: LocaleKeys.view_all.tr(), + onSubtitleTapped: () { + context.read().onNavbarTapped(0); + context.read().applyFilterOnBranches(index: 0); + }).horPaddingMain(), + Consumer(builder: (BuildContext context, AppointmentsVM appointmentsVM, Widget? child) { + return ServiceProviderWidget(nearbyBranches: context.read().nearbyBranches).horPaddingMain(); + }), + Consumer( + builder: (BuildContext context, AdVM adVM, Widget? child) { + return Column( + children: [ + if (adVM.myActiveAdsForHome.isNotEmpty) ...[ + Column( + children: [ + 15.height, + ViewAllWidget( + title: LocaleKeys.my_active_Ads.tr().toUpperCase(), + subTitle: LocaleKeys.view_all.tr(), + onSubtitleTapped: () { + context.read().onNavbarTapped(3); + context.read().updateIsExploreAds(false); + }).horPaddingMain(), + BuildAdsList( + shouldShowAdStatus: true, + isAdsFragment: false, + adsList: adVM.myActiveAdsForHome, + scrollPhysics: NeverScrollableScrollPhysics(), + ), + ], + ) + ], + if (adVM.exploreAds.isNotEmpty) ...[ + Column( + children: [ + 15.height, + ViewAllWidget( + title: LocaleKeys.myRecommendedAds.tr().toUpperCase(), subTitle: LocaleKeys.view_all.tr(), onSubtitleTapped: () { context.read().onNavbarTapped(3); - context.read().updateIsExploreAds(false); - }).horPaddingMain(), - BuildAdsList( - shouldShowAdStatus: true, - isAdsFragment: false, - adsList: adVM.myActiveAdsForHome, - scrollPhysics: NeverScrollableScrollPhysics(), - ), - ], - ) + context.read().updateIsExploreAds(true); + context.read().applyFilterOnExploreAds(createdByRoleFilter: CreatedByRoleEnum.allAds); + }, + ).horPaddingMain(), + BuildAdsList( + shouldShowAdStatus: false, + adsList: adVM.exploreAds.length >= 3 ? adVM.exploreAds.take(3).toList() : adVM.exploreAds, + isAdsFragment: false, + scrollPhysics: NeverScrollableScrollPhysics(), + ), + ], + ) + ] ], - if (adVM.exploreAds.isNotEmpty) ...[ - Column( - children: [ - 15.height, - ViewAllWidget( - title: LocaleKeys.myRecommendedAds.tr().toUpperCase(), - subTitle: LocaleKeys.view_all.tr(), - onSubtitleTapped: () { - context.read().onNavbarTapped(3); - context.read().updateIsExploreAds(true); - context.read().applyFilterOnExploreAds(createdByRoleFilter: CreatedByRoleEnum.allAds); - }, - ).horPaddingMain(), - BuildAdsList( - shouldShowAdStatus: false, - adsList: adVM.exploreAds.length >= 3 ? adVM.exploreAds.take(3).toList() : adVM.exploreAds, - isAdsFragment: false, - scrollPhysics: NeverScrollableScrollPhysics(), - ), - ], - ) - ] - ], - ); - }, - ), - 20.height, - ], + ); + }, + ), + 20.height, + ], + ), ), ), ),