From c0051cc79e718e418dc27145cb789d324eee2a6b Mon Sep 17 00:00:00 2001 From: dzc <2388224167@qq.com> Date: Tue, 18 Mar 2025 16:05:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E4=B8=8B=E8=BD=BD=E5=9B=BE=E7=89=87?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/common/utils/app/app_network_tool.dart | 22 ++++++++++++++++------ lib/common/widgets/app/app_img.dart | 2 +- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/lib/common/utils/app/app_network_tool.dart b/lib/common/utils/app/app_network_tool.dart index a1cd1f3..88d0a99 100644 --- a/lib/common/utils/app/app_network_tool.dart +++ b/lib/common/utils/app/app_network_tool.dart @@ -10,7 +10,7 @@ import 'package:image/image.dart' as imglib; import 'package:pj_supermarket_cloud/common/index.dart'; abstract class AppNetworkTool { - static const _tag = "判断是否有网络"; + static const _tag = "网络工具类"; static StreamSubscription>? subscription; @@ -117,11 +117,21 @@ abstract class AppNetworkTool { networkImage = "${Constants.ossUrl}$networkImage"; } try { - final response = await http - .get(Uri.parse(networkImage)) - .timeout(const Duration(seconds: 30)); - if (response.statusCode != 200) return null; - return response.bodyBytes; + final client = http.Client(); + try { + final request = http.Request('GET', Uri.parse(networkImage)); + final streamedResponse = await client.send(request).timeout( + const Duration(seconds: 30), + ); + if (streamedResponse.statusCode != 200) return null; + final List bytes = []; + await for (final chunk in streamedResponse.stream) { + bytes.addAll(chunk); + } + return Uint8List.fromList(bytes); + } finally { + client.close(); + } } catch (e) { logger.e('|$_tag|从网络中下载图片错误:|$e|'); return null; diff --git a/lib/common/widgets/app/app_img.dart b/lib/common/widgets/app/app_img.dart index cc3b819..532e4ce 100644 --- a/lib/common/widgets/app/app_img.dart +++ b/lib/common/widgets/app/app_img.dart @@ -59,7 +59,7 @@ Widget appImg( double width = 100, double height = 100, double errorSize = 20, - BoxFit fit = BoxFit.cover, + BoxFit fit = BoxFit.contain, }) { if (ObjectUtil.isEmpty(src)) { return appEmptyIcon(Get.context!);