Add debug logging for PUT requests and profile updates in AccountSettingsDialog

This commit is contained in:
Leon Bösche
2026-01-29 03:53:04 +01:00
parent 62a23b5fb0
commit 49d8d2ea7b
2 changed files with 46 additions and 18 deletions

View File

@@ -146,10 +146,19 @@ class ApiClient {
}
Future<Map<String, dynamic>> 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);
}
}

View File

@@ -102,19 +102,25 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
}
Future<void> _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<ApiClient>();
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
@@ -125,27 +131,23 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
if (mounted) {
// Update auth state
print('🔄 Updating auth state');
context.read<AuthBloc>().add(UpdateUserProfile(updatedUser));
// Show success message after the build cycle
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
const SnackBar(content: Text('Profile updated successfully')),
);
}
});
// 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 after the build cycle
WidgetsBinding.instance.addPostFrameCallback((_) {
if (mounted) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(content: Text('Failed to update profile: $e')),
);
}
});
// Show error message
print('📢 Showing error snackbar');
ScaffoldMessenger.of(
context,
).showSnackBar(SnackBar(content: Text('Failed to update profile: $e')));
}
} finally {
setState(() => _isLoading = false);
@@ -580,8 +582,25 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
child: SizedBox(
width: 144,
child: ModernGlassButton(
onPressed: _updateProfile,
child: const Text('Save Changes'),
onPressed: _isLoading
? () {}
: () {
print('🔘 Save Changes button pressed');
_updateProfile();
},
isLoading: _isLoading,
child: _isLoading
? const SizedBox(
width: 20,
height: 20,
child: CircularProgressIndicator(
strokeWidth: 2,
valueColor: AlwaysStoppedAnimation<Color>(
Colors.white,
),
),
)
: const Text('Save Changes'),
),
),
),