From b55d277406f228b892ece3b6df4d6e63f81253e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Thu, 29 Jan 2026 04:00:33 +0100 Subject: [PATCH] Refactor API client logging and enhance user data handling in AccountSettingsDialog --- b0esche_cloud/lib/services/api_client.dart | 9 ----- .../lib/widgets/account_settings_dialog.dart | 39 ++++++++++--------- 2 files changed, 20 insertions(+), 28 deletions(-) diff --git a/b0esche_cloud/lib/services/api_client.dart b/b0esche_cloud/lib/services/api_client.dart index 66ce75b..b255bcc 100644 --- a/b0esche_cloud/lib/services/api_client.dart +++ b/b0esche_cloud/lib/services/api_client.dart @@ -146,19 +146,10 @@ class ApiClient { } Future> putRaw(String path, {dynamic data}) async { - print('🌐 PUT request to: $path'); - print('📦 Data: $data'); try { final response = await _dio.put(path, data: data); - print('📨 Response status: ${response.statusCode}'); - print('📨 Response data: ${response.data}'); return response.data; } on DioException catch (e) { - print('❌ PUT request failed: ${e.message}'); - if (e.response != null) { - print('❌ Response status: ${e.response?.statusCode}'); - print('❌ Response data: ${e.response?.data}'); - } throw _handleError(e); } } diff --git a/b0esche_cloud/lib/widgets/account_settings_dialog.dart b/b0esche_cloud/lib/widgets/account_settings_dialog.dart index 6e3f823..3365616 100644 --- a/b0esche_cloud/lib/widgets/account_settings_dialog.dart +++ b/b0esche_cloud/lib/widgets/account_settings_dialog.dart @@ -41,6 +41,18 @@ class _AccountSettingsDialogState extends State { _currentPasswordController = TextEditingController(); _newPasswordController = TextEditingController(); _confirmPasswordController = TextEditingController(); + + // Get initial user data + WidgetsBinding.instance.addPostFrameCallback((_) { + if (mounted) { + final authState = context.read().state; + if (authState is AuthAuthenticated) { + _currentUser = authState.user; + _displayNameController.text = _currentUser?.displayName ?? ''; + _avatarUrl = _currentUser?.avatarUrl; + } + } + }); } @override @@ -102,25 +114,19 @@ class _AccountSettingsDialogState extends State { } Future _updateProfile() async { - print( - '🔄 _updateProfile called with displayName: "${_displayNameController.text}"', - ); if (_currentUser == null) { - print('❌ _currentUser is null'); return; } setState(() => _isLoading = true); try { final apiClient = GetIt.I(); - print('📡 Making API call to updateUserProfile'); await apiClient.updateUserProfile( displayName: _displayNameController.text.isEmpty ? null : _displayNameController.text, avatarUrl: _avatarUrl, ); - print('✅ API call successful'); final updatedUser = _currentUser!.copyWith( displayName: _displayNameController.text.isEmpty @@ -131,20 +137,16 @@ class _AccountSettingsDialogState extends State { if (mounted) { // Update auth state - print('🔄 Updating auth state'); context.read().add(UpdateUserProfile(updatedUser)); // Show success message - print('📢 Showing success snackbar'); ScaffoldMessenger.of(context).showSnackBar( const SnackBar(content: Text('Profile updated successfully')), ); } } catch (e) { - print('❌ API call failed: $e'); if (mounted) { // Show error message - print('📢 Showing error snackbar'); ScaffoldMessenger.of( context, ).showSnackBar(SnackBar(content: Text('Failed to update profile: $e'))); @@ -347,10 +349,14 @@ class _AccountSettingsDialogState extends State { Widget build(BuildContext context) { return BlocBuilder( builder: (context, authState) { - // Update user data when auth state changes - if (authState is AuthAuthenticated && _currentUser != authState.user) { + // Always ensure we have the current user + if (authState is AuthAuthenticated) { _currentUser = authState.user; - _displayNameController.text = _currentUser?.displayName ?? ''; + // Only update controller if it's empty (first time) or if user changed + if (_displayNameController.text.isEmpty || + _currentUser?.displayName != _displayNameController.text) { + _displayNameController.text = _currentUser?.displayName ?? ''; + } _avatarUrl = _currentUser?.avatarUrl; } @@ -582,12 +588,7 @@ class _AccountSettingsDialogState extends State { child: SizedBox( width: 144, child: ModernGlassButton( - onPressed: _isLoading - ? () {} - : () { - print('🔘 Save Changes button pressed'); - _updateProfile(); - }, + onPressed: _isLoading ? () {} : _updateProfile, isLoading: _isLoading, child: _isLoading ? const SizedBox(