[英]Images are not loaded even after network is restored before scrolling in flutter
Image(
image: NetworkImage(widget.contentImageLink[0]),
height: 200,
fit: BoxFit.cover,
errorBuilder: (context, error, stackTrace) {
return Container(
height: 200,
color: Colors.grey.shade900,
);
},
),
The above code display container when there's not internet and supposed to load image when network is restored but it doesn't load the image on it's own unless I scroll the listView to move it out of screen.上面的代码在没有互联网时显示容器,并且应该在网络恢复时加载图像,但它不会自行加载图像,除非我滚动 listView 将其移出屏幕。 When scrolled back it loads the images.
向后滚动时,它会加载图像。
How can I make it load images ASA network is restored?如何使其加载图像 ASA 网络已恢复?
You can use connectivity_plus: ^2.3.0
to check if the connection is reestablished.您可以使用
connectivity_plus: ^2.3.0
来检查连接是否重新建立。 Just add this listener to your widget and call setState(){} when the connection is reestablished.只需将此侦听器添加到您的小部件并在重新建立连接时调用 setState(){}。
late StreamSubscription _subscription;
@override
initState() {
_subscription = Connectivity().onConnectivityChanged.listen(
(result) {
if (result == ConnectivityResult.wifi ||
result == ConnectivityResult.mobile ||
result == ConnectivityResult.ethernet) {
setState(){}
}
},
);
}
@override
dispose() {
_subscription.cancel();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.