fix(mining): handle avatar URL vs SVG in mining page
This commit is contained in:
parent
91e54946ba
commit
526f90d33e
|
|
@ -463,14 +463,48 @@ class _MiningPageState extends ConsumerState<MiningPage> {
|
|||
}
|
||||
|
||||
/// 构建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>(Color(0xFFD4AF37)),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const Icon(
|
||||
Icons.person,
|
||||
size: 40,
|
||||
color: Color(0xFF8B5A2B),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
// 检测是否是 SVG 字符串(随机生成的 SVG 头像)
|
||||
if (_avatarSvg!.contains('<svg') || _avatarSvg!.startsWith('<?xml')) {
|
||||
return SvgPicture.string(
|
||||
_avatarSvg!,
|
||||
width: 80,
|
||||
height: 80,
|
||||
fit: BoxFit.cover,
|
||||
);
|
||||
}
|
||||
}
|
||||
return const Icon(
|
||||
Icons.person,
|
||||
|
|
|
|||
Loading…
Reference in New Issue