fix(mobile): sync avatar from API when local storage is empty

When recovering an account via mnemonic, the avatar SVG might not be
saved to local storage. Now the profile page checks if avatarUrl is
returned from the /me API and updates both the display and local storage.

- Add updateLocalAvatarSvg() method to AccountService
- Update _loadMeData() to sync avatar from API response

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
hailin 2025-12-09 18:19:13 -08:00
parent 7f2511227f
commit 8d94d9e4bb
2 changed files with 19 additions and 1 deletions

View File

@ -689,6 +689,14 @@ class AccountService {
return result;
}
/// SVG
/// API
Future<void> updateLocalAvatarSvg(String avatarSvg) async {
debugPrint('$_tag updateLocalAvatarSvg() - 更新本地头像 SVG (长度: ${avatarSvg.length})');
await _secureStorage.write(key: StorageKeys.avatarSvg, value: avatarSvg);
debugPrint('$_tag updateLocalAvatarSvg() - 保存成功');
}
///
Future<String?> getReferralCode() async {
debugPrint('$_tag getReferralCode() - 获取推荐码');

View File

@ -198,6 +198,12 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
if (meData.referralCode.isNotEmpty) {
_referralCode = meData.referralCode;
}
// API返回了头像
if (_avatarSvg == null && meData.avatarUrl != null && meData.avatarUrl!.isNotEmpty) {
_avatarSvg = meData.avatarUrl;
// API获取
accountService.updateLocalAvatarSvg(meData.avatarUrl!);
}
});
}
} catch (e) {
@ -209,6 +215,7 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
/// (from referral-service)
Future<void> _loadReferralData() async {
try {
debugPrint('[ProfilePage] 开始加载推荐数据...');
final referralService = ref.read(referralServiceProvider);
//
@ -220,6 +227,8 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
final referralInfo = results[0] as ReferralInfoResponse;
final directReferrals = results[1] as DirectReferralsResponse;
debugPrint('[ProfilePage] 推荐数据加载成功: directReferralCount=${referralInfo.directReferralCount}, totalTeamCount=${referralInfo.totalTeamCount}');
if (mounted) {
setState(() {
_directReferralCount = referralInfo.directReferralCount;
@ -237,8 +246,9 @@ class _ProfilePageState extends ConsumerState<ProfilePage> {
}).toList();
});
}
} catch (e) {
} catch (e, stackTrace) {
debugPrint('[ProfilePage] 加载推荐数据失败: $e');
debugPrint('[ProfilePage] 堆栈: $stackTrace');
//
}
}