@@ -26,22 +26,6 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
2626 final TextEditingController _usernameController = TextEditingController ();
2727 XFile ? _selectedImage; // To hold the newly selected image for upload
2828
29- @override
30- void didChangeDependencies () {
31- super .didChangeDependencies ();
32- // Initialize controllers with current user data when dependencies change
33- final supabaseService = Provider .of <SupabaseService >(
34- context,
35- listen: false ,
36- );
37- if (supabaseService.currentUser != null ) {
38- _nameController.text = supabaseService.currentUser! .name ?? '' ;
39- _emailController.text = supabaseService.currentUser! .email;
40- _usernameController.text = supabaseService.currentUser! .username ?? '' ;
41- // No need to fetch image here, CachedNetworkImage handles it
42- }
43- }
44-
4529 @override
4630 void dispose () {
4731 _nameController.dispose ();
@@ -65,8 +49,6 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
6549 context,
6650 listen: false ,
6751 );
68- final String currentUserId =
69- supabaseService.currentUser! .id; // Ensure user is logged in
7052
7153 // Update Name and Username
7254 if (_nameController.text != supabaseService.currentUser! .name ||
@@ -105,12 +87,12 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
10587 // Upload Profile Picture if a new one was selected
10688 if (_selectedImage != null ) {
10789 try {
108- final res = await supabaseService.uploadUserProfilePicture (
90+ await supabaseService.uploadUserProfilePicture (
10991 _selectedImage! ,
11092 );
11193 ScaffoldMessenger .of (
11294 context,
113- ).showSnackBar (SnackBar (content: Text ('Profile picture updated!' )));
95+ ).showSnackBar (const SnackBar (content: Text ('Profile picture updated!' )));
11496 setState (() {
11597 _selectedImage = null ; // Clear selected image after upload
11698 });
@@ -120,12 +102,9 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
120102 ).showSnackBar (SnackBar (content: Text (e.toString ())));
121103 }
122104 }
123-
124- // Optionally, refresh user data to ensure everything is in sync
105+
106+ // Refresh user data from Supabase to ensure UI is in sync
125107 await supabaseService.supabase.auth.refreshSession ();
126-
127- // Close the dialog after saving
128- // Navigator.of(context).pop();
129108 }
130109
131110 @override
@@ -136,11 +115,16 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
136115 return Consumer2 <DashboardProvider , SupabaseService >(
137116 builder: (context, dashboardProvider, supabaseService, child) {
138117 final currentUser = supabaseService.currentUser;
118+
119+ // Update controllers with the current state of the provider
120+ _nameController.text = currentUser? .name ?? '' ;
121+ _emailController.text = currentUser? .email ?? '' ;
122+ _usernameController.text = currentUser? .username ?? '' ;
123+
139124 final String displayAvatarUrl =
140125 _selectedImage != null
141- ? _selectedImage!
142- .path // Show locally selected image immediately
143- : currentUser? .avatarUrl ?? '' ; // Fallback to network or empty
126+ ? _selectedImage! .path
127+ : currentUser? .avatarUrl ?? '' ;
144128
145129 return Dialog (
146130 backgroundColor: Theme .of (context).cardColor,
@@ -189,8 +173,7 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
189173 child: ClipOval (
190174 child:
191175 displayAvatarUrl.isNotEmpty
192- ? (_selectedImage !=
193- null // If a new image is selected, display it from path/memory
176+ ? (_selectedImage != null
194177 ? (kIsWeb
195178 ? Image .network (
196179 displayAvatarUrl,
@@ -201,7 +184,6 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
201184 fit: BoxFit .cover,
202185 ))
203186 : CachedNetworkImage (
204- // Otherwise, display from network cache
205187 imageUrl: displayAvatarUrl,
206188 fit: BoxFit .cover,
207189 placeholder:
@@ -225,10 +207,10 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
225207 bottom: 0 ,
226208 right: 0 ,
227209 child: InkWell (
228- onTap: _pickImage, // Call image picker
210+ onTap: _pickImage,
229211 child: Container (
230212 width:
231- 28 , // Slightly larger for better tap target
213+ 28 ,
232214 height: 28 ,
233215 decoration: BoxDecoration (
234216 color: Theme .of (context).primaryColor,
@@ -249,8 +231,8 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
249231 ],
250232 ),
251233 deviceType == rh.DeviceType .desktop
252- ? const SizedBox (height : 16 )
253- : const SizedBox (height : 8 ),
234+ ? const SizedBox (width : 16 )
235+ : const SizedBox (width : 8 ),
254236 Column (
255237 crossAxisAlignment: CrossAxisAlignment .start,
256238 children: [
@@ -596,4 +578,4 @@ class _ProfileSettingsWidgetState extends State<ProfileSettingsWidget> {
596578 ),
597579 );
598580 }
599- }
581+ }
0 commit comments