gpt4 book ai didi

Flutter CachedNetworkImage 错误 : (CacheManager: Failed to download file) and (SocketException or HttpException)

转载 作者:行者123 更新时间:2023-12-04 12:02:10 29 4
gpt4 key购买 nike

我正在使用 cached_network_image图书馆。如果我这样设置:

void main() {
runApp(MyApp());
}

class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
print('MyApp building');
return MaterialApp(
home: Scaffold(
body: HomeWidget(),
),
);
}
}

class HomeWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Center(
child: Container(
child: CachedNetworkImage(
imageUrl: "https://example.com/image/whatever.png",
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
),
),
);
}
}
使用无效的 URL(因为它返回 404 或服务器拒绝连接),然后我的 IDE 卡住并给出以下错误之一:
HttpExceptionWithStatus (HttpException: Invalid statusCode: 404, uri = https://example.com/image/whatever.png)
或者这个(如果我把它改成一个不存在的主机):
SocketException (SocketException: Failed host lookup: 'ksdhfkajsdhfkashdfkadshfk.com' (OS Error: No address associated with hostname, errno = 7))
enter image description here
我期望的是 CachedNetworkImage小部件只显示 errorWidget ,但事实并非如此。

最佳答案

cached_network_image的创建者说( source ):

If you have break on exceptions enabled the debugger stops, but that's because the dart VM doesn't always know whether an exception is caught or not. If you continue this still shouldn't freeze your app.


那是我需要的 key 。这只是调试器停止。您可以点击继续按钮或禁用停止未捕获的异常。 CachedNetworkImage然后小部件将显示 errorWidget正如预期的那样。
在 VS Code 中,您可以在调试面板的左下角取消选中此项。
enter image description here
enter image description here
我相信基于 this post 的 Android Studio 中也有类似的设置.

关于Flutter CachedNetworkImage 错误 : (CacheManager: Failed to download file) and (SocketException or HttpException),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65732967/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com