From 7dbb1dce3f3d627623498a0db9a6a2f92eda03f3 Mon Sep 17 00:00:00 2001 From: Sultan khan Date: Mon, 10 Aug 2026 18:07:34 +0300 Subject: [PATCH] crashlytics fixes --- .../profile_picture_view_model.dart | 30 ++++--------------- lib/presentation/home/landing_page.dart | 29 ++++++++++++++---- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/lib/features/profile_picture/profile_picture_view_model.dart b/lib/features/profile_picture/profile_picture_view_model.dart index 017ca5d8..59198809 100644 --- a/lib/features/profile_picture/profile_picture_view_model.dart +++ b/lib/features/profile_picture/profile_picture_view_model.dart @@ -70,9 +70,7 @@ class ProfilePictureViewModel extends ChangeNotifier { try { _cachedImageBytes = base64Decode(imageData); _cachedImageDataHash = '${imageData.length}_${imageData.hashCode}'; - print('โœ… Cached existing profile image'); } catch (e) { - print('โŒ Error caching existing image: $e'); _cachedImageBytes = null; _cachedImageDataHash = null; } @@ -85,7 +83,6 @@ class ProfilePictureViewModel extends ChangeNotifier { final currentPatientId = _appState.getAuthenticatedUser()?.patientId; if (currentPatientId != null && currentPatientId != _currentPatientId) { - print('๐Ÿ”„ User switched detected: $_currentPatientId -> $currentPatientId'); _handleUserSwitch(currentPatientId); return true; } @@ -97,8 +94,6 @@ class ProfilePictureViewModel extends ChangeNotifier { final oldPatientId = _currentPatientId; _currentPatientId = newPatientId; - print('๐Ÿงน Clearing cache for old user: $oldPatientId'); - // Clear AppState cache _appState.clearProfileImageCache(); @@ -113,17 +108,14 @@ class ProfilePictureViewModel extends ChangeNotifier { notifyListeners(); // Load new user's profile image - print('๐Ÿ“ฅ Loading profile image for new user: $newPatientId'); _profileSettingsViewModel.getProfileImage( patientID: newPatientId, forceRefresh: true, onSuccess: (data) { - print('โœ… Profile image loaded successfully for user: $newPatientId'); _tryCacheExistingImage(); notifyListeners(); }, onError: (error) { - print('โŒ Error loading profile image: $error'); notifyListeners(); }, ); @@ -133,22 +125,18 @@ class ProfilePictureViewModel extends ChangeNotifier { void loadProfileImage({bool forceRefresh = false}) { // Check if profile image is already loaded in AppState (skip if forcing refresh) if (!forceRefresh && _appState.getProfileImageData != null && _appState.getProfileImageData!.isNotEmpty) { - print('โœ… Profile image already cached in AppState'); return; } final patientID = _appState.getAuthenticatedUser()?.patientId; if (patientID == null) { - print('โš ๏ธ Cannot load profile image - no authenticated user'); return; } - print('๐Ÿ“ฅ Loading profile image for patient: $patientID (forceRefresh: $forceRefresh)'); _profileSettingsViewModel.getProfileImage( patientID: patientID, forceRefresh: forceRefresh, onSuccess: (data) { - print('โœ… Profile image loaded successfully'); _tryCacheExistingImage(); notifyListeners(); }, @@ -188,10 +176,6 @@ class ProfilePictureViewModel extends ChangeNotifier { false, // Don't show files option, only camera and gallery (base64String, file) async { try { - print('=== Starting image processing ==='); - print('File path: ${file.path}'); - print('File exists: ${await file.exists()}'); - print('Original file size: ${await file.length() / 1024} KB'); // Compress and resize the image print('Calling compressAndResizeImage...'); @@ -266,14 +250,10 @@ class ProfilePictureViewModel extends ChangeNotifier { onError('No authenticated user found'); return; } - - print('๐Ÿ“ค Uploading profile image for patient: $patientID'); _profileSettingsViewModel.uploadProfileImage( patientID: patientID, imageData: base64String, onSuccess: (data) async { - print('โœ… Profile image uploaded successfully'); - // Clear old cache first to ensure fresh data _cachedImageBytes = null; _cachedImageDataHash = null; @@ -287,9 +267,13 @@ class ProfilePictureViewModel extends ChangeNotifier { // Increment version to trigger targeted rebuild (no full screen refresh) _profileImageVersion.value++; - print('๐Ÿ”„ Profile image version updated to ${_profileImageVersion.value} (targeted rebuild)'); - onSuccess(data); + final String successMessage = data is String + ? data + : (data is Map && data['message'] != null + ? data['message'].toString() + : data?.toString() ?? 'Success'); + onSuccess(successMessage); }, onError: (error) { print('โŒ Error uploading profile image: $error'); @@ -308,7 +292,6 @@ class ProfilePictureViewModel extends ChangeNotifier { try { _cachedImageBytes = base64Decode(imageData!); _cachedImageDataHash = currentHash; - print('๐Ÿ”„ Updated cached image bytes'); } catch (e) { print('โŒ Error decoding profile image: $e'); _cachedImageBytes = null; @@ -326,7 +309,6 @@ class ProfilePictureViewModel extends ChangeNotifier { _cachedImageDataHash = null; _selectedImage = null; notifyListeners(); - print('๐Ÿงน Cleared all profile picture cache'); } /// Check if we should show shimmer loading diff --git a/lib/presentation/home/landing_page.dart b/lib/presentation/home/landing_page.dart index b3ba5e78..60d55fb8 100644 --- a/lib/presentation/home/landing_page.dart +++ b/lib/presentation/home/landing_page.dart @@ -120,12 +120,23 @@ class _LandingPageState extends State { authVM = context.read(); habibWalletVM = context.read(); appointmentRatingViewModel = context.read(); + appState = getIt.get(); authVM.savePushTokenToAppState(); if (mounted) { - authVM.checkLastLoginStatus(() { - showQuickLogin(context); - }); + final user = appState.getAuthenticatedUser(); + final hasUserQuickLoginData = + user != null && + (user.mobileNumber?.isNotEmpty ?? false) && + (user.patientIdentificationNo?.isNotEmpty ?? false); + + if (hasUserQuickLoginData) { + authVM.checkLastLoginStatus(() { + if (mounted) { + showQuickLogin(context); + } + }); + } } _scrollController.addListener(() { @@ -172,12 +183,19 @@ class _LandingPageState extends State { appointmentNo, projectID, onSuccess: ((response) { + // Only open dialog if details are loaded AND widget is mounted + if (!mounted || appointmentRatingViewModel.appointmentDetails == null) return; + appointmentRatingViewModel.setClinicOrDoctor(false); - appointmentRatingViewModel.setTitle(LocaleKeys.rateDoctor.tr(context: context)); - appointmentRatingViewModel.setSubTitle(LocaleKeys.howWasYourLastVisitWithDoctor.tr(context: context)); + appointmentRatingViewModel.setTitle(LocaleKeys.rateDoctor.tr()); + appointmentRatingViewModel.setSubTitle(LocaleKeys.howWasYourLastVisitWithDoctor.tr()); openLastRating(); appState.setRatedVisible(true); }), + onError: (String errorMessage) { + // Silently mark as rated to prevent retry loops + if (mounted) appState.setRatedVisible(true); + }, ); } }, @@ -1458,6 +1476,7 @@ class _LandingPageState extends State { } openLastRating() { + if (!mounted) return; showCommonBottomSheetWithoutHeight( context, titleWidget: Selector( -- 2.30.2