Show user name in Account screen instead of User #ID
- Load user profile on Account screen init - Display FirstName LastInitial format - Fall back to User #ID if profile fails to load Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
7f30b77112
commit
7b08fa73de
1 changed files with 23 additions and 1 deletions
|
|
@ -19,6 +19,7 @@ class _AccountScreenState extends State<AccountScreen> {
|
|||
bool _isLoadingAvatar = true;
|
||||
bool _isUploadingAvatar = false;
|
||||
String? _avatarUrl;
|
||||
String? _userName;
|
||||
|
||||
final ImagePicker _picker = ImagePicker();
|
||||
|
||||
|
|
@ -26,6 +27,7 @@ class _AccountScreenState extends State<AccountScreen> {
|
|||
void initState() {
|
||||
super.initState();
|
||||
_loadAvatar();
|
||||
_loadProfile();
|
||||
}
|
||||
|
||||
Future<void> _loadAvatar() async {
|
||||
|
|
@ -52,6 +54,26 @@ class _AccountScreenState extends State<AccountScreen> {
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> _loadProfile() async {
|
||||
final appState = context.read<AppState>();
|
||||
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<void> _pickAndUploadAvatar() async {
|
||||
// Check if user is logged in first
|
||||
final appState = context.read<AppState>();
|
||||
|
|
@ -354,7 +376,7 @@ class _AccountScreenState extends State<AccountScreen> {
|
|||
_buildAvatar(),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'User #${appState.userId ?? "?"}',
|
||||
_userName ?? 'User #${appState.userId ?? "?"}',
|
||||
style: Theme.of(context).textTheme.titleLarge,
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue