feat:下载图片优化
This commit is contained in:
1 parent
6dc478077a
commit
c0051cc79e
2 files changed
+17
-7
No files matched your search
@@ -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<List<ConnectivityResult>>? 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<int> 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;
|
||||
|
||||
@@ -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!);
|
||||
|
||||
Reference in new issue
Block a user