diff --git a/b0esche_cloud/lib/widgets/account_settings_dialog.dart b/b0esche_cloud/lib/widgets/account_settings_dialog.dart index c0ed0d0..30fe399 100644 --- a/b0esche_cloud/lib/widgets/account_settings_dialog.dart +++ b/b0esche_cloud/lib/widgets/account_settings_dialog.dart @@ -41,7 +41,6 @@ class _AccountSettingsDialogState extends State { _currentPasswordController = TextEditingController(); _newPasswordController = TextEditingController(); _confirmPasswordController = TextEditingController(); - _loadUserData(); } @override @@ -53,15 +52,6 @@ class _AccountSettingsDialogState extends State { super.dispose(); } - void _loadUserData() { - final authState = context.read().state; - if (authState is AuthAuthenticated) { - _currentUser = authState.user; - _displayNameController.text = _currentUser?.displayName ?? ''; - _avatarUrl = _currentUser?.avatarUrl; - } - } - Future _pickAndUploadAvatar() async { try { final result = await FilePicker.platform.pickFiles( @@ -135,12 +125,16 @@ class _AccountSettingsDialogState extends State { // Update auth state context.read().add(UpdateUserProfile(updatedUser)); - ScaffoldMessenger.of( - context, - ).showSnackBar(const SnackBar(content: Text('Profile updated'))); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Profile updated successfully')), + ); } } catch (e) { - setState(() => _error = e.toString()); + if (mounted) { + ScaffoldMessenger.of( + context, + ).showSnackBar(SnackBar(content: Text('Failed to update profile: $e'))); + } } finally { setState(() => _isLoading = false); } @@ -148,7 +142,11 @@ class _AccountSettingsDialogState extends State { Future _changePassword() async { if (_newPasswordController.text != _confirmPasswordController.text) { - setState(() => _error = 'Passwords do not match'); + if (mounted) { + ScaffoldMessenger.of( + context, + ).showSnackBar(const SnackBar(content: Text('Passwords do not match'))); + } return; } @@ -160,9 +158,9 @@ class _AccountSettingsDialogState extends State { newPassword: _newPasswordController.text, ); if (mounted) { - ScaffoldMessenger.of( - context, - ).showSnackBar(const SnackBar(content: Text('Password changed'))); + ScaffoldMessenger.of(context).showSnackBar( + const SnackBar(content: Text('Password changed successfully')), + ); } // Clear fields @@ -170,7 +168,11 @@ class _AccountSettingsDialogState extends State { _newPasswordController.clear(); _confirmPasswordController.clear(); } catch (e) { - setState(() => _error = e.toString()); + if (mounted) { + ScaffoldMessenger.of(context).showSnackBar( + SnackBar(content: Text('Failed to change password: $e')), + ); + } } finally { setState(() => _isLoading = false); } @@ -329,79 +331,92 @@ class _AccountSettingsDialogState extends State { @override Widget build(BuildContext context) { - return Dialog( - backgroundColor: AppTheme.primaryBackground, - shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)), - child: Container( - width: 500, - height: 700, - padding: const EdgeInsets.all(24), - child: Column( - children: [ - // Header - Row( + return BlocBuilder( + builder: (context, authState) { + // Update user data when auth state changes + if (authState is AuthAuthenticated && _currentUser != authState.user) { + _currentUser = authState.user; + _displayNameController.text = _currentUser?.displayName ?? ''; + _avatarUrl = _currentUser?.avatarUrl; + } + + return Dialog( + backgroundColor: AppTheme.primaryBackground, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(16), + ), + child: Container( + width: 500, + height: 700, + padding: const EdgeInsets.all(24), + child: Column( children: [ - Text( - 'Account Settings', - style: TextStyle( - color: AppTheme.primaryText, - fontSize: 24, - fontWeight: FontWeight.bold, - ), + // Header + Row( + children: [ + Text( + 'Account Settings', + style: TextStyle( + color: AppTheme.primaryText, + fontSize: 24, + fontWeight: FontWeight.bold, + ), + ), + const Spacer(), + IconButton( + onPressed: () => Navigator.of(context).pop(), + icon: Icon(Icons.close, color: AppTheme.secondaryText), + splashColor: Colors.transparent, + highlightColor: Colors.transparent, + ), + ], ), - const Spacer(), - IconButton( - onPressed: () => Navigator.of(context).pop(), - icon: Icon(Icons.close, color: AppTheme.secondaryText), - splashColor: Colors.transparent, - highlightColor: Colors.transparent, + const SizedBox(height: 16), + + // Tabs + Row( + children: [ + _buildTabButton('Profile', 0), + _buildTabButton('Security', 1), + _buildTabButton('Subscription', 2), + ], + ), + const SizedBox(height: 16), + + // Content + Expanded( + child: _isLoading + ? Center( + child: CircularProgressIndicator( + color: AppTheme.accentColor, + ), + ) + : _error != null + ? Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Text( + _error!, + style: TextStyle(color: AppTheme.errorColor), + ), + const SizedBox(height: 16), + ModernGlassButton( + onPressed: () { + setState(() => _error = null); + }, + child: const Text('Retry'), + ), + ], + ), + ) + : _buildTabContent(), ), ], ), - const SizedBox(height: 16), - - // Tabs - Row( - children: [ - _buildTabButton('Profile', 0), - _buildTabButton('Security', 1), - _buildTabButton('Subscription', 2), - ], - ), - const SizedBox(height: 16), - - // Content - Expanded( - child: _isLoading - ? Center( - child: CircularProgressIndicator( - color: AppTheme.accentColor, - ), - ) - : _error != null - ? Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Text( - _error!, - style: TextStyle(color: AppTheme.errorColor), - ), - const SizedBox(height: 16), - ModernGlassButton( - onPressed: () { - setState(() => _error = null); - }, - child: const Text('Retry'), - ), - ], - ), - ) - : _buildTabContent(), - ), - ], - ), - ), + ), + ); + }, ); }