Files
feature-next-arch/lib/core/utils/image_url_util.dart
Songzex 7c01229b9e 1:修复远程遥控控制状态显示不正确的问题
2:更换端口映射为测试服的8081-59003,9001-59004
2026-08-26 14:23:20 +08:00

25 lines
914 B
Dart
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import 'package:maibu_satabot_v2/core/consts/http_api_consts.dart';
/// 图片地址工具:后端返回的图片路径可能是相对路径(如 /profile/avatar/xxx.jpg),
/// 直接交给 Image.network 会因缺少 host 抛 "No host specified in URI" 异常。
/// 此工具负责将相对路径拼接成完整的服务器地址。
class ImageUrlUtil {
ImageUrlUtil._();
/// 补全图片地址
/// - 已是完整 http(s) 地址:原样返回
/// - 以 / 开头的相对路径:拼接 baseUrl
/// - 其他相对路径:拼接 baseUrl + /
/// - null 或空:返回 null
static String? resolve(String? path) {
if (path == null || path.isEmpty) return null;
if (path.startsWith('http://') || path.startsWith('https://')) {
return path;
}
if (path.startsWith('/')) {
return '${HttpApiConsts.baseUrl}$path';
}
return '${HttpApiConsts.baseUrl}/$path';
}
}