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:
parent
7f2511227f
commit
8d94d9e4bb
|
|
@ -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() - 获取推荐码');
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
// 失败时保持默认数据
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue