crashlytics fixes

dev_sultan
Sultan khan 1 week ago
parent d2718c1e27
commit 7dbb1dce3f

@ -70,9 +70,7 @@ class ProfilePictureViewModel extends ChangeNotifier {
try { try {
_cachedImageBytes = base64Decode(imageData); _cachedImageBytes = base64Decode(imageData);
_cachedImageDataHash = '${imageData.length}_${imageData.hashCode}'; _cachedImageDataHash = '${imageData.length}_${imageData.hashCode}';
print('✅ Cached existing profile image');
} catch (e) { } catch (e) {
print('❌ Error caching existing image: $e');
_cachedImageBytes = null; _cachedImageBytes = null;
_cachedImageDataHash = null; _cachedImageDataHash = null;
} }
@ -85,7 +83,6 @@ class ProfilePictureViewModel extends ChangeNotifier {
final currentPatientId = _appState.getAuthenticatedUser()?.patientId; final currentPatientId = _appState.getAuthenticatedUser()?.patientId;
if (currentPatientId != null && currentPatientId != _currentPatientId) { if (currentPatientId != null && currentPatientId != _currentPatientId) {
print('🔄 User switched detected: $_currentPatientId -> $currentPatientId');
_handleUserSwitch(currentPatientId); _handleUserSwitch(currentPatientId);
return true; return true;
} }
@ -97,8 +94,6 @@ class ProfilePictureViewModel extends ChangeNotifier {
final oldPatientId = _currentPatientId; final oldPatientId = _currentPatientId;
_currentPatientId = newPatientId; _currentPatientId = newPatientId;
print('🧹 Clearing cache for old user: $oldPatientId');
// Clear AppState cache // Clear AppState cache
_appState.clearProfileImageCache(); _appState.clearProfileImageCache();
@ -113,17 +108,14 @@ class ProfilePictureViewModel extends ChangeNotifier {
notifyListeners(); notifyListeners();
// Load new user's profile image // Load new user's profile image
print('📥 Loading profile image for new user: $newPatientId');
_profileSettingsViewModel.getProfileImage( _profileSettingsViewModel.getProfileImage(
patientID: newPatientId, patientID: newPatientId,
forceRefresh: true, forceRefresh: true,
onSuccess: (data) { onSuccess: (data) {
print('✅ Profile image loaded successfully for user: $newPatientId');
_tryCacheExistingImage(); _tryCacheExistingImage();
notifyListeners(); notifyListeners();
}, },
onError: (error) { onError: (error) {
print('❌ Error loading profile image: $error');
notifyListeners(); notifyListeners();
}, },
); );
@ -133,22 +125,18 @@ class ProfilePictureViewModel extends ChangeNotifier {
void loadProfileImage({bool forceRefresh = false}) { void loadProfileImage({bool forceRefresh = false}) {
// Check if profile image is already loaded in AppState (skip if forcing refresh) // Check if profile image is already loaded in AppState (skip if forcing refresh)
if (!forceRefresh && _appState.getProfileImageData != null && _appState.getProfileImageData!.isNotEmpty) { if (!forceRefresh && _appState.getProfileImageData != null && _appState.getProfileImageData!.isNotEmpty) {
print('✅ Profile image already cached in AppState');
return; return;
} }
final patientID = _appState.getAuthenticatedUser()?.patientId; final patientID = _appState.getAuthenticatedUser()?.patientId;
if (patientID == null) { if (patientID == null) {
print('⚠️ Cannot load profile image - no authenticated user');
return; return;
} }
print('📥 Loading profile image for patient: $patientID (forceRefresh: $forceRefresh)');
_profileSettingsViewModel.getProfileImage( _profileSettingsViewModel.getProfileImage(
patientID: patientID, patientID: patientID,
forceRefresh: forceRefresh, forceRefresh: forceRefresh,
onSuccess: (data) { onSuccess: (data) {
print('✅ Profile image loaded successfully');
_tryCacheExistingImage(); _tryCacheExistingImage();
notifyListeners(); notifyListeners();
}, },
@ -188,10 +176,6 @@ class ProfilePictureViewModel extends ChangeNotifier {
false, // Don't show files option, only camera and gallery false, // Don't show files option, only camera and gallery
(base64String, file) async { (base64String, file) async {
try { 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 // Compress and resize the image
print('Calling compressAndResizeImage...'); print('Calling compressAndResizeImage...');
@ -266,14 +250,10 @@ class ProfilePictureViewModel extends ChangeNotifier {
onError('No authenticated user found'); onError('No authenticated user found');
return; return;
} }
print('📤 Uploading profile image for patient: $patientID');
_profileSettingsViewModel.uploadProfileImage( _profileSettingsViewModel.uploadProfileImage(
patientID: patientID, patientID: patientID,
imageData: base64String, imageData: base64String,
onSuccess: (data) async { onSuccess: (data) async {
print('✅ Profile image uploaded successfully');
// Clear old cache first to ensure fresh data // Clear old cache first to ensure fresh data
_cachedImageBytes = null; _cachedImageBytes = null;
_cachedImageDataHash = null; _cachedImageDataHash = null;
@ -287,9 +267,13 @@ class ProfilePictureViewModel extends ChangeNotifier {
// Increment version to trigger targeted rebuild (no full screen refresh) // Increment version to trigger targeted rebuild (no full screen refresh)
_profileImageVersion.value++; _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) { onError: (error) {
print('❌ Error uploading profile image: $error'); print('❌ Error uploading profile image: $error');
@ -308,7 +292,6 @@ class ProfilePictureViewModel extends ChangeNotifier {
try { try {
_cachedImageBytes = base64Decode(imageData!); _cachedImageBytes = base64Decode(imageData!);
_cachedImageDataHash = currentHash; _cachedImageDataHash = currentHash;
print('🔄 Updated cached image bytes');
} catch (e) { } catch (e) {
print('❌ Error decoding profile image: $e'); print('❌ Error decoding profile image: $e');
_cachedImageBytes = null; _cachedImageBytes = null;
@ -326,7 +309,6 @@ class ProfilePictureViewModel extends ChangeNotifier {
_cachedImageDataHash = null; _cachedImageDataHash = null;
_selectedImage = null; _selectedImage = null;
notifyListeners(); notifyListeners();
print('🧹 Cleared all profile picture cache');
} }
/// Check if we should show shimmer loading /// Check if we should show shimmer loading

@ -120,12 +120,23 @@ class _LandingPageState extends State<LandingPage> {
authVM = context.read<AuthenticationViewModel>(); authVM = context.read<AuthenticationViewModel>();
habibWalletVM = context.read<HabibWalletViewModel>(); habibWalletVM = context.read<HabibWalletViewModel>();
appointmentRatingViewModel = context.read<AppointmentRatingViewModel>(); appointmentRatingViewModel = context.read<AppointmentRatingViewModel>();
appState = getIt.get<AppState>();
authVM.savePushTokenToAppState(); authVM.savePushTokenToAppState();
if (mounted) { if (mounted) {
authVM.checkLastLoginStatus(() { final user = appState.getAuthenticatedUser();
showQuickLogin(context); final hasUserQuickLoginData =
}); user != null &&
(user.mobileNumber?.isNotEmpty ?? false) &&
(user.patientIdentificationNo?.isNotEmpty ?? false);
if (hasUserQuickLoginData) {
authVM.checkLastLoginStatus(() {
if (mounted) {
showQuickLogin(context);
}
});
}
} }
_scrollController.addListener(() { _scrollController.addListener(() {
@ -172,12 +183,19 @@ class _LandingPageState extends State<LandingPage> {
appointmentNo, appointmentNo,
projectID, projectID,
onSuccess: ((response) { onSuccess: ((response) {
// Only open dialog if details are loaded AND widget is mounted
if (!mounted || appointmentRatingViewModel.appointmentDetails == null) return;
appointmentRatingViewModel.setClinicOrDoctor(false); appointmentRatingViewModel.setClinicOrDoctor(false);
appointmentRatingViewModel.setTitle(LocaleKeys.rateDoctor.tr(context: context)); appointmentRatingViewModel.setTitle(LocaleKeys.rateDoctor.tr());
appointmentRatingViewModel.setSubTitle(LocaleKeys.howWasYourLastVisitWithDoctor.tr(context: context)); appointmentRatingViewModel.setSubTitle(LocaleKeys.howWasYourLastVisitWithDoctor.tr());
openLastRating(); openLastRating();
appState.setRatedVisible(true); 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<LandingPage> {
} }
openLastRating() { openLastRating() {
if (!mounted) return;
showCommonBottomSheetWithoutHeight( showCommonBottomSheetWithoutHeight(
context, context,
titleWidget: Selector<AppointmentRatingViewModel, String?>( titleWidget: Selector<AppointmentRatingViewModel, String?>(

Loading…
Cancel
Save