From 526f90d33e37e32baf41b2d2a189268c739e2eec Mon Sep 17 00:00:00 2001 From: hailin Date: Tue, 9 Dec 2025 18:56:58 -0800 Subject: [PATCH] fix(mining): handle avatar URL vs SVG in mining page --- .../presentation/pages/mining_page.dart | 48 ++++++++++++++++--- 1 file changed, 41 insertions(+), 7 deletions(-) diff --git a/frontend/mobile-app/lib/features/mining/presentation/pages/mining_page.dart b/frontend/mobile-app/lib/features/mining/presentation/pages/mining_page.dart index a5a40438..84f8a9dd 100644 --- a/frontend/mobile-app/lib/features/mining/presentation/pages/mining_page.dart +++ b/frontend/mobile-app/lib/features/mining/presentation/pages/mining_page.dart @@ -463,14 +463,48 @@ class _MiningPageState extends ConsumerState { } /// 构建SVG或默认头像 + /// 注意:_avatarSvg 可能存储的是 URL(用户上传的图片)或 SVG 字符串(随机生成的头像) Widget _buildSvgOrDefaultAvatar() { - if (_avatarSvg != null) { - return SvgPicture.string( - _avatarSvg!, - width: 80, - height: 80, - fit: BoxFit.cover, - ); + if (_avatarSvg != null && _avatarSvg!.isNotEmpty) { + // 检测是否是 URL(用户上传的头像图片) + if (_avatarSvg!.startsWith('http://') || _avatarSvg!.startsWith('https://')) { + return Image.network( + _avatarSvg!, + width: 80, + height: 80, + fit: BoxFit.cover, + loadingBuilder: (context, child, loadingProgress) { + if (loadingProgress == null) return child; + return const Center( + child: SizedBox( + width: 24, + height: 24, + child: CircularProgressIndicator( + strokeWidth: 2, + valueColor: AlwaysStoppedAnimation(Color(0xFFD4AF37)), + ), + ), + ); + }, + errorBuilder: (context, error, stackTrace) { + return const Icon( + Icons.person, + size: 40, + color: Color(0xFF8B5A2B), + ); + }, + ); + } + + // 检测是否是 SVG 字符串(随机生成的 SVG 头像) + if (_avatarSvg!.contains('