Add debug logging for PUT requests and profile updates in AccountSettingsDialog
This commit is contained in:
@@ -146,10 +146,19 @@ class ApiClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<Map<String, dynamic>> putRaw(String path, {dynamic data}) async {
|
Future<Map<String, dynamic>> putRaw(String path, {dynamic data}) async {
|
||||||
|
print('🌐 PUT request to: $path');
|
||||||
|
print('📦 Data: $data');
|
||||||
try {
|
try {
|
||||||
final response = await _dio.put(path, data: data);
|
final response = await _dio.put(path, data: data);
|
||||||
|
print('📨 Response status: ${response.statusCode}');
|
||||||
|
print('📨 Response data: ${response.data}');
|
||||||
return response.data;
|
return response.data;
|
||||||
} on DioException catch (e) {
|
} 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);
|
throw _handleError(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,19 +102,25 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _updateProfile() async {
|
Future<void> _updateProfile() async {
|
||||||
|
print(
|
||||||
|
'🔄 _updateProfile called with displayName: "${_displayNameController.text}"',
|
||||||
|
);
|
||||||
if (_currentUser == null) {
|
if (_currentUser == null) {
|
||||||
|
print('❌ _currentUser is null');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setState(() => _isLoading = true);
|
setState(() => _isLoading = true);
|
||||||
try {
|
try {
|
||||||
final apiClient = GetIt.I<ApiClient>();
|
final apiClient = GetIt.I<ApiClient>();
|
||||||
|
print('📡 Making API call to updateUserProfile');
|
||||||
await apiClient.updateUserProfile(
|
await apiClient.updateUserProfile(
|
||||||
displayName: _displayNameController.text.isEmpty
|
displayName: _displayNameController.text.isEmpty
|
||||||
? null
|
? null
|
||||||
: _displayNameController.text,
|
: _displayNameController.text,
|
||||||
avatarUrl: _avatarUrl,
|
avatarUrl: _avatarUrl,
|
||||||
);
|
);
|
||||||
|
print('✅ API call successful');
|
||||||
|
|
||||||
final updatedUser = _currentUser!.copyWith(
|
final updatedUser = _currentUser!.copyWith(
|
||||||
displayName: _displayNameController.text.isEmpty
|
displayName: _displayNameController.text.isEmpty
|
||||||
@@ -125,27 +131,23 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
|
|||||||
|
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
// Update auth state
|
// Update auth state
|
||||||
|
print('🔄 Updating auth state');
|
||||||
context.read<AuthBloc>().add(UpdateUserProfile(updatedUser));
|
context.read<AuthBloc>().add(UpdateUserProfile(updatedUser));
|
||||||
|
|
||||||
// Show success message after the build cycle
|
// Show success message
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
print('📢 Showing success snackbar');
|
||||||
if (mounted) {
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
const SnackBar(content: Text('Profile updated successfully')),
|
const SnackBar(content: Text('Profile updated successfully')),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
|
print('❌ API call failed: $e');
|
||||||
if (mounted) {
|
if (mounted) {
|
||||||
// Show error message after the build cycle
|
// Show error message
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
print('📢 Showing error snackbar');
|
||||||
if (mounted) {
|
ScaffoldMessenger.of(
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
context,
|
||||||
SnackBar(content: Text('Failed to update profile: $e')),
|
).showSnackBar(SnackBar(content: Text('Failed to update profile: $e')));
|
||||||
);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setState(() => _isLoading = false);
|
setState(() => _isLoading = false);
|
||||||
@@ -580,8 +582,25 @@ class _AccountSettingsDialogState extends State<AccountSettingsDialog> {
|
|||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 144,
|
width: 144,
|
||||||
child: ModernGlassButton(
|
child: ModernGlassButton(
|
||||||
onPressed: _updateProfile,
|
onPressed: _isLoading
|
||||||
child: const Text('Save Changes'),
|
? () {}
|
||||||
|
: () {
|
||||||
|
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'),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
Reference in New Issue
Block a user