diff --git a/lib/screens/account_screen.dart b/lib/screens/account_screen.dart index ccb99ac..8261c73 100644 --- a/lib/screens/account_screen.dart +++ b/lib/screens/account_screen.dart @@ -19,6 +19,7 @@ class _AccountScreenState extends State { bool _isLoadingAvatar = true; bool _isUploadingAvatar = false; String? _avatarUrl; + String? _userName; final ImagePicker _picker = ImagePicker(); @@ -26,6 +27,7 @@ class _AccountScreenState extends State { void initState() { super.initState(); _loadAvatar(); + _loadProfile(); } Future _loadAvatar() async { @@ -52,6 +54,26 @@ class _AccountScreenState extends State { } } + Future _loadProfile() async { + final appState = context.read(); + if (!appState.isLoggedIn) return; + + try { + final profile = await Api.getProfile(); + if (mounted) { + final firstName = profile.firstName; + final lastInitial = profile.lastName.isNotEmpty + ? '${profile.lastName[0]}.' + : ''; + setState(() { + _userName = '$firstName $lastInitial'.trim(); + }); + } + } catch (e) { + debugPrint('Error loading profile: $e'); + } + } + Future _pickAndUploadAvatar() async { // Check if user is logged in first final appState = context.read(); @@ -354,7 +376,7 @@ class _AccountScreenState extends State { _buildAvatar(), const SizedBox(height: 16), Text( - 'User #${appState.userId ?? "?"}', + _userName ?? 'User #${appState.userId ?? "?"}', style: Theme.of(context).textTheme.titleLarge, ), const SizedBox(height: 4),